Documentation

APCuAdapter
in package
implements CacheAdapterInterface

APCu cache adapter for shared memory caching.

Provides high-performance caching using APCu extension for single-server environments. Requires the APCu PHP extension.

Table of Contents

Interfaces

CacheAdapterInterface
Interface for cache adapters in the Canvas LMS SDK.

Properties

$available  : bool
$prefix  : string
$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.
getInfo()  : array<string, mixed>
Get APCu cache information.
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.
checkAvailability()  : void
Check if APCu is available and enabled.
clearOldEntries()  : int
Clear old entries to free up space.
patternToRegex()  : string
Convert a pattern with wildcards to a regex.

Properties

$available

private bool $available

Whether APCu is available

$stats

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

Cache statistics

Methods

__construct()

Constructor.

public __construct([string $prefix = 'canvas:' ]) : mixed
Parameters
$prefix : string = 'canvas:'

Cache key prefix to avoid collisions

Tags
throws
RuntimeException

If APCu extension is not available

clear()

Clear all items from the cache.

public clear() : void

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

getInfo()

Get APCu cache information.

public getInfo() : array<string, mixed>
Return values
array<string, mixed>

Detailed cache information

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)

checkAvailability()

Check if APCu is available and enabled.

private checkAvailability() : void
Tags
throws
RuntimeException

If APCu is not available

clearOldEntries()

Clear old entries to free up space.

private clearOldEntries() : int

This method removes entries that haven't been accessed recently.

Return values
int

Number of entries cleared

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