FileSystemAdapter
in package
implements
CacheAdapterInterface
File system cache adapter for persistent storage.
Stores cache entries as files on disk with automatic cleanup of expired entries.
Table of Contents
Interfaces
- CacheAdapterInterface
- Interface for cache adapters in the Canvas LMS SDK.
Properties
- $cacheDir : string
- $compression : bool
- $dirPermissions : int
- $filePermissions : int
- $stats : array{hits: int, misses: int}
Methods
- __construct() : mixed
- Constructor.
- cleanExpired() : int
- Clean up expired cache entries.
- 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.
- deleteDirectory() : void
- Recursively delete a directory.
- ensureCacheDirectoryExists() : void
- Ensure the cache directory exists.
- getFilePath() : string
- Get the file path for a cache key.
- patternToRegex() : string
- Convert a pattern with wildcards to a regex.
Properties
$cacheDir
private
string
$cacheDir
Cache directory path
$compression
private
bool
$compression
Enable compression
$dirPermissions
private
int
$dirPermissions
Directory permissions
$filePermissions
private
int
$filePermissions
File permissions
$stats
private
array{hits: int, misses: int}
$stats
= ['hits' => 0, 'misses' => 0]
Cache statistics
Methods
__construct()
Constructor.
public
__construct([string $cacheDir = '/tmp/canvas-cache' ][, bool $compression = true ][, int $dirPermissions = 0755 ][, int $filePermissions = 0644 ]) : mixed
Parameters
- $cacheDir : string = '/tmp/canvas-cache'
-
Cache directory path
- $compression : bool = true
-
Enable gzip compression
- $dirPermissions : int = 0755
-
Directory permissions (octal)
- $filePermissions : int = 0644
-
File permissions (octal)
cleanExpired()
Clean up expired cache entries.
public
cleanExpired() : int
Return values
int —Number of entries cleaned
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>|nullgetStats()
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)
deleteDirectory()
Recursively delete a directory.
private
deleteDirectory(string $dir[, bool $deleteRoot = true ]) : void
Parameters
- $dir : string
-
The directory path
- $deleteRoot : bool = true
-
Whether to delete the root directory
ensureCacheDirectoryExists()
Ensure the cache directory exists.
private
ensureCacheDirectoryExists() : void
getFilePath()
Get the file path for a cache key.
private
getFilePath(string $key) : string
Parameters
- $key : string
-
The cache key
Return values
string —The file path
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