Documentation

TtlStrategy
in package

Determines appropriate TTL (Time To Live) values for different Canvas API resources.

Provides intelligent TTL defaults based on resource type and allows per-request overrides.

Table of Contents

Properties

$defaultTtl  : int
$rules  : array<string, int>

Methods

__construct()  : mixed
Constructor.
addRule()  : void
Add or update a TTL rule.
getDefaultTtl()  : int
Get the default TTL.
getRules()  : array<string, int>
Get all TTL rules.
getTtl()  : int
Get the TTL for a request.
removeRule()  : void
Remove a TTL rule.
setDefaultTtl()  : void
Set the default TTL.
getTtlForPath()  : int
Get the TTL for a specific path.

Properties

$defaultTtl

private int $defaultTtl

Default TTL in seconds

$rules

private array<string, int> $rules = [ // Static resources - 1 hour '/courses$' => 3600, '/accounts' => 3600, '/terms' => 3600, '/roles' => 3600, // Semi-static resources - 15 minutes '/enrollments' => 900, '/sections' => 900, '/users$' => 900, '/groups$' => 900, // Dynamic resources - 5 minutes '/assignments' => 300, '/modules' => 300, '/pages' => 300, '/discussions' => 300, '/announcements' => 300, '/files' => 300, '/folders' => 300, // Real-time resources - 1 minute or no cache '/submissions' => 60, '/grades' => 0, '/quiz_submissions' => 0, '/progress' => 0, '/live_assessments' => 0, // Specific course resources '/courses/\d+$' => 900, // Individual course - 15 minutes '/courses/\d+/students' => 300, // Course students - 5 minutes '/courses/\d+/activity_stream' => 60, ]

TTL rules for different endpoint patterns

Methods

__construct()

Constructor.

public __construct([int $defaultTtl = 300 ]) : mixed
Parameters
$defaultTtl : int = 300

Default TTL in seconds (default: 300)

addRule()

Add or update a TTL rule.

public addRule(string $pattern, int $ttl) : void
Parameters
$pattern : string

The URL pattern (regex)

$ttl : int

The TTL in seconds

getDefaultTtl()

Get the default TTL.

public getDefaultTtl() : int
Return values
int

The default TTL in seconds

getRules()

Get all TTL rules.

public getRules() : array<string, int>
Return values
array<string, int>

The TTL rules

getTtl()

Get the TTL for a request.

public getTtl(RequestInterface $request[, array<string, mixed> $options = [] ]) : int
Parameters
$request : RequestInterface

The HTTP request

$options : array<string, mixed> = []

Request options

Return values
int

The TTL in seconds (0 = no cache)

removeRule()

Remove a TTL rule.

public removeRule(string $pattern) : void
Parameters
$pattern : string

The URL pattern to remove

setDefaultTtl()

Set the default TTL.

public setDefaultTtl(int $ttl) : void
Parameters
$ttl : int

The default TTL in seconds

getTtlForPath()

Get the TTL for a specific path.

private getTtlForPath(string $path) : int
Parameters
$path : string

The URL path

Return values
int

The TTL in seconds


        
On this page

Search results