class FileStore implements CanFlushLocks, LockProvider, Store

Traits

Fallback implementations for stores without native multi-key operations.

Constants

protected PERMANENT_TIMESTAMP

The expiration timestamp stored for items cached forever.

Properties

protected Filesystem $files

The Filesystem instance.

protected string $directory

The file cache directory.

protected string|null $lockDirectory

The file cache lock directory.

protected int|null $filePermission

Octal representation of the cache file permissions.

protected array|bool|null $serializableClasses

The classes that should be allowed during unserialization.

protected SerializableClassPolicy|null $serializableClassPolicy

The shared serializable class policy.

Methods

int
secondsUntil(DateInterval|DateTimeInterface|int $delay)

Get the number of seconds until the given DateTime.

int
availableAt(DateInterval|DateTimeInterface|int|null $delay = 0)

Get the "available at" UNIX timestamp.

parseDateInterval(DateInterval|DateTimeInterface|int|null $delay)

If the given value is an interval, convert it to a DateTime instance.

int
currentTime()

Get the current system time as a UNIX timestamp.

string
runTimeForHumans(float $startTime, float|null $endTime = null)

Given a start time, format the total run time for human readability.

array
many(array $keys)

Retrieve multiple items from the cache by key.

bool
putMany(array $values, int $seconds)

Store multiple items in the cache for a given number of seconds.

__construct(Filesystem $files, string $directory, int|null $filePermission = null, array|bool|null $serializableClasses = null, SerializableClassPolicy|null $serializableClassPolicy = null)

Create a new file cache store instance.

mixed
get(string $key)

Retrieve an item from the cache by key.

bool
put(string $key, mixed $value, int $seconds)

Store an item in the cache for a given number of seconds.

bool
add(string $key, mixed $value, int $seconds)

Store an item in the cache if the key doesn't exist.

bool
refreshIfOwned(string $key, string $expectedOwner, int $seconds)

Atomically refresh the expiration of a cache key if it matches the expected owner.

float|null
remainingSeconds(string $key)

Get the number of seconds until the given key expires.

bool|int
increment(string $key, int $value = 1)

Increment the value of an item in the cache.

bool|int
decrement(string $key, int $value = 1)

Decrement the value of an item in the cache.

bool
forever(string $key, mixed $value)

Store an item in the cache indefinitely.

lock(string $name, int $seconds = 0, string|null $owner = null)

Get a lock instance.

restoreLock(string $name, string $owner)

Restore a lock instance using the owner identifier.

bool
touch(string $key, int $seconds)

Adjust the expiration time of a cached item.

bool
forget(string $key)

Remove an item from the cache.

bool
flush()

Remove all items from the cache.

bool
supportsFlushingLocks()

Determine if the store can currently flush locks.

bool
flushLocks()

Remove all locks from the store.

getFilesystem()

Get the Filesystem instance.

string
getDirectory()

Get the working directory of the cache.

setDirectory(string $directory)

Set the working directory of the cache.

setLockDirectory(string|null $lockDirectory)

Set the cache directory where locks should be stored.

string
getPrefix()

Get the cache key prefix.

void
ensureCacheDirectoryExists(string $path)

Create the file cache directory if necessary.

void
ensurePermissionsAreCorrect(string $path)

Ensure the created node has the correct permissions.

array
getPayload(string $key)

Retrieve an item and expiry time from the cache by key.

mixed
unserialize(string $value)

Unserialize the given value.

array
emptyPayload()

Get a default empty payload for the cache.

string
path(string $key)

Get the full path for the given cache key.

int
expiration(int $seconds)

Get the expiration time based on the given seconds.

string
expirationHeader(int $seconds)

Get the fixed-width expiration header for a cache item.

bool
hasSeparateLockStore()

Determine if the lock store is separate from the cache store.

Details

in InteractsWithTime at line 17
protected int secondsUntil(DateInterval|DateTimeInterface|int $delay)

Get the number of seconds until the given DateTime.

Parameters

DateInterval|DateTimeInterface|int $delay

Return Value

int

in InteractsWithTime at line 29
protected int availableAt(DateInterval|DateTimeInterface|int|null $delay = 0)

Get the "available at" UNIX timestamp.

Parameters

DateInterval|DateTimeInterface|int|null $delay

Return Value

int

in InteractsWithTime at line 41
protected DateTimeInterface|int parseDateInterval(DateInterval|DateTimeInterface|int|null $delay)

If the given value is an interval, convert it to a DateTime instance.

Parameters

DateInterval|DateTimeInterface|int|null $delay

Return Value

DateTimeInterface|int

in InteractsWithTime at line 57
protected int currentTime()

Get the current system time as a UNIX timestamp.

Return Value

int

in InteractsWithTime at line 65
protected string runTimeForHumans(float $startTime, float|null $endTime = null)

Given a start time, format the total run time for human readability.

Parameters

float $startTime
float|null $endTime

Return Value

string

array many(array $keys)

Retrieve multiple items from the cache by key.

Items not found in the cache will have a null value.

Parameters

array $keys

Return Value

array

bool putMany(array $values, int $seconds)

Store multiple items in the cache for a given number of seconds.

Parameters

array $values
int $seconds

Return Value

bool

at line 60
__construct(Filesystem $files, string $directory, int|null $filePermission = null, array|bool|null $serializableClasses = null, SerializableClassPolicy|null $serializableClassPolicy = null)

Create a new file cache store instance.

Parameters

Filesystem $files
string $directory
int|null $filePermission
array|bool|null $serializableClasses
SerializableClassPolicy|null $serializableClassPolicy

at line 77
mixed get(string $key)

Retrieve an item from the cache by key.

Parameters

string $key

Return Value

mixed

at line 85
bool put(string $key, mixed $value, int $seconds)

Store an item in the cache for a given number of seconds.

Parameters

string $key
mixed $value
int $seconds

Return Value

bool

at line 107
bool add(string $key, mixed $value, int $seconds)

Store an item in the cache if the key doesn't exist.

Parameters

string $key
mixed $value
int $seconds

Return Value

bool

at line 141
bool refreshIfOwned(string $key, string $expectedOwner, int $seconds)

Atomically refresh the expiration of a cache key if it matches the expected owner.

Parameters

string $key
string $expectedOwner
int $seconds

Return Value

bool

at line 184
float|null remainingSeconds(string $key)

Get the number of seconds until the given key expires.

Parameters

string $key

Return Value

float|null

at line 204
bool|int increment(string $key, int $value = 1)

Increment the value of an item in the cache.

Parameters

string $key
int $value

Return Value

bool|int

at line 216
bool|int decrement(string $key, int $value = 1)

Decrement the value of an item in the cache.

Parameters

string $key
int $value

Return Value

bool|int

at line 224
bool forever(string $key, mixed $value)

Store an item in the cache indefinitely.

Parameters

string $key
mixed $value

Return Value

bool

at line 232
Lock lock(string $name, int $seconds = 0, string|null $owner = null)

Get a lock instance.

Parameters

string $name
int $seconds
string|null $owner

Return Value

Lock

at line 253
Lock restoreLock(string $name, string $owner)

Restore a lock instance using the owner identifier.

Parameters

string $name
string $owner

Return Value

Lock

at line 261
bool touch(string $key, int $seconds)

Adjust the expiration time of a cached item.

Parameters

string $key
int $seconds

Return Value

bool

at line 275
bool forget(string $key)

Remove an item from the cache.

Parameters

string $key

Return Value

bool

at line 291
bool flush()

Remove all items from the cache.

Return Value

bool

at line 311
bool supportsFlushingLocks()

Determine if the store can currently flush locks.

Return Value

bool

at line 321
bool flushLocks()

Remove all locks from the store.

Return Value

bool

Exceptions

RuntimeException

at line 345
Filesystem getFilesystem()

Get the Filesystem instance.

Return Value

Filesystem

at line 353
string getDirectory()

Get the working directory of the cache.

Return Value

string

at line 364
FileStore setDirectory(string $directory)

Set the working directory of the cache.

Boot-only. Persists on the cached store for the worker lifetime; per-request use races across coroutines.

Parameters

string $directory

Return Value

FileStore

at line 377
FileStore setLockDirectory(string|null $lockDirectory)

Set the cache directory where locks should be stored.

Boot-only. Persists on the cached store for the worker lifetime; per-request use races across coroutines.

Parameters

string|null $lockDirectory

Return Value

FileStore

at line 387
string getPrefix()

Get the cache key prefix.

Return Value

string

at line 395
protected void ensureCacheDirectoryExists(string $path)

Create the file cache directory if necessary.

Parameters

string $path

Return Value

void

at line 411
protected void ensurePermissionsAreCorrect(string $path)

Ensure the created node has the correct permissions.

Parameters

string $path

Return Value

void

at line 424
protected array getPayload(string $key)

Retrieve an item and expiry time from the cache by key.

Parameters

string $key

Return Value

array

at line 469
protected mixed unserialize(string $value)

Unserialize the given value.

Parameters

string $value

Return Value

mixed

at line 485
protected array emptyPayload()

Get a default empty payload for the cache.

Return Value

array

at line 493
string path(string $key)

Get the full path for the given cache key.

Parameters

string $key

Return Value

string

at line 503
protected int expiration(int $seconds)

Get the expiration time based on the given seconds.

Parameters

int $seconds

Return Value

int

at line 513
protected string expirationHeader(int $seconds)

Get the fixed-width expiration header for a cache item.

Parameters

int $seconds

Return Value

string

at line 521
bool hasSeparateLockStore()

Determine if the lock store is separate from the cache store.

Return Value

bool