Documentation

InMemoryAdapter
in package
implements CacheAdapterInterface

In-memory cache adapter for development and testing.

This adapter stores cache entries in a PHP array that exists only for the duration of the request. It's the default adapter and provides a no-op caching behavior without persistence.

Table of Contents

Interfaces

CacheAdapterInterface
Interface for cache adapters in the Canvas LMS SDK.

Properties

$cache  : array<string, array{data: array, expires: int}>
$cacheMemoryUsage  : int
$maxEntries  : int
$stats  : array{hits: int, misses: int}

Methods

__construct()  : mixed
Constructor.
clear()  : void
Clear all items from the cache.
delete()  : bool
Delete an item from the cache.
deleteByPattern()  : int
Delete items matching a pattern.
get()  : array<string, mixed>|null
Retrieve an item from the cache.
getStats()  : array{hits: int, misses: int, size: int, entries: int}
Get cache statistics.
has()  : bool
Check if an item exists in the cache.
set()  : void
Store an item in the cache.
cleanExpired()  : void
Remove expired entries from the cache.
evictOldest()  : void
Evict the oldest cache entry.
patternToRegex()  : string
Convert a pattern with wildcards to a regex.

Properties

$cache

private array<string, array{data: array, expires: int}> $cache = []

Cache storage

$cacheMemoryUsage

private int $cacheMemoryUsage = 0

Track approximate memory usage of cached data

$maxEntries

private int $maxEntries

Maximum number of cache entries (0 = unlimited)

$stats

private array{hits: int, misses: int} $stats = ['hits' => 0, 'misses' => 0]

Cache statistics

Methods

__construct()

Constructor.

public __construct([int $maxEntries = 1000 ]) : mixed
Parameters
$maxEntries : int = 1000

Maximum number of cache entries (0 = unlimited)

delete()

Delete an item from the cache.

public delete(string $key) : bool
Parameters
$key : string

The cache key

Return values
bool

True if deleted, false if not found

deleteByPattern()

Delete items matching a pattern.

public deleteByPattern(string $pattern) : int
Parameters
$pattern : string

The pattern to match (supports * wildcards)

Return values
int

The number of items deleted

get()

Retrieve an item from the cache.

public get(string $key) : array<string, mixed>|null
Parameters
$key : string

The cache key

Return values
array<string, mixed>|null

getStats()

Get cache statistics.

public getStats() : array{hits: int, misses: int, size: int, entries: int}
Return values
array{hits: int, misses: int, size: int, entries: int}

has()

Check if an item exists in the cache.

public has(string $key) : bool
Parameters
$key : string

The cache key

Return values
bool

True if the item exists and is not expired

set()

Store an item in the cache.

public set(string $key, array<string, mixed> $data[, int $ttl = 0 ]) : void
Parameters
$key : string

The cache key

$data : array<string, mixed>
$ttl : int = 0

Time to live in seconds (0 = infinite)

cleanExpired()

Remove expired entries from the cache.

private cleanExpired() : void

evictOldest()

Evict the oldest cache entry.

private evictOldest() : void

patternToRegex()

Convert a pattern with wildcards to a regex.

private patternToRegex(string $pattern) : string
Parameters
$pattern : string

The pattern with * wildcards

Return values
string

The regex pattern


        
On this page

Search results