FileStore
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
Get the number of seconds until the given DateTime.
Get the "available at" UNIX timestamp.
If the given value is an interval, convert it to a DateTime instance.
Given a start time, format the total run time for human readability.
Store multiple items in the cache for a given number of seconds.
Create a new file cache store instance.
Retrieve an item from the cache by key.
Store an item in the cache for a given number of seconds.
Store an item in the cache if the key doesn't exist.
Atomically refresh the expiration of a cache key if it matches the expected owner.
Read the owner of a live lock without removing its file.
Remove a lock file only while its expected owner holds it.
Get the number of seconds until the given key expires.
Increment the value of an item in the cache.
Decrement the value of an item in the cache.
Store an item in the cache indefinitely.
Restore a lock instance using the owner identifier.
Adjust the expiration time of a cached item.
Remove an item from the cache.
Remove all items from the cache.
Determine if the store can currently flush locks.
Remove all locks from the store.
Get the Filesystem instance.
Get the working directory of the cache.
Set the working directory of the cache.
Set the cache directory where locks should be stored.
Get the cache key prefix.
Create the file cache directory if necessary.
Ensure the created node has the correct permissions.
Store an item with an absolute expiration timestamp.
Retrieve an item and expiry time from the cache by key.
Unserialize the given value.
Get a default empty payload for the cache.
Get the full path for the given cache key.
Get the expiration time based on the given seconds.
Get the fixed-width expiration header for a cache item.
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.
in
InteractsWithTime at line 29
protected int
availableAt(DateInterval|DateTimeInterface|int|null $delay = 0)
Get the "available at" UNIX timestamp.
in
InteractsWithTime at line 47
protected DateTimeInterface|int
parseDateInterval(DateInterval|DateTimeInterface|int|null $delay)
If the given value is an interval, convert it to a DateTime instance.
in
InteractsWithTime at line 63
protected int
currentTime()
Get the current system time as a UNIX timestamp.
in
InteractsWithTime at line 71
protected string
runTimeForHumans(float $startTime, float|null $endTime = null)
Given a start time, format the total run time for human readability.
in
RetrievesMultipleKeys at line 25
array
many(array $keys)
Retrieve multiple items from the cache by key.
Items not found in the cache will have a null value.
in
RetrievesMultipleKeys at line 44
bool
putMany(array $values, int $seconds)
Store multiple items in the cache for a given number of seconds.
at line 62
__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.
at line 79
mixed
get(string $key)
Retrieve an item from the cache by key.
at line 87
bool
put(string $key, mixed $value, int $seconds)
Store an item in the cache for a given number of seconds.
at line 95
bool
add(string $key, mixed $value, int $seconds)
Store an item in the cache if the key doesn't exist.
at line 136
bool
refreshIfOwned(string $key, string $expectedOwner, int $seconds)
Atomically refresh the expiration of a cache key if it matches the expected owner.
at line 186
string|null
getLockOwner(string $key)
Read the owner of a live lock without removing its file.
at line 208
bool
forgetIfOwned(string $key, string $expectedOwner)
Remove a lock file only while its expected owner holds it.
at line 241
float|null
remainingSeconds(string $key)
Get the number of seconds until the given key expires.
at line 265
bool|int
increment(string $key, int $value = 1)
Increment the value of an item in the cache.
at line 284
bool|int
decrement(string $key, int $value = 1)
Decrement the value of an item in the cache.
at line 292
bool
forever(string $key, mixed $value)
Store an item in the cache indefinitely.
at line 300
Lock
lock(string $name, int $seconds = 0, string|null $owner = null)
Get a lock instance.
at line 321
Lock
restoreLock(string $name, string $owner)
Restore a lock instance using the owner identifier.
at line 329
bool
touch(string $key, int $seconds)
Adjust the expiration time of a cached item.
at line 343
bool
forget(string $key)
Remove an item from the cache.
at line 359
bool
flush()
Remove all items from the cache.
at line 379
bool
supportsFlushingLocks()
Determine if the store can currently flush locks.
at line 389
bool
flushLocks()
Remove all locks from the store.
at line 413
Filesystem
getFilesystem()
Get the Filesystem instance.
at line 421
string
getDirectory()
Get the working directory of the cache.
at line 434
FileStore
setDirectory(string $directory)
Set the working directory of the cache.
Persists on the cached store for the worker lifetime; per-request use races across coroutines.
at line 450
FileStore
setLockDirectory(string|null $lockDirectory)
Set the cache directory where locks should be stored.
Persists on the cached store for the worker lifetime; per-request use races across coroutines.
at line 461
string
getPrefix()
Get the cache key prefix.
at line 469
protected void
ensureCacheDirectoryExists(string $path)
Create the file cache directory if necessary.
at line 485
protected void
ensurePermissionsAreCorrect(string $path)
Ensure the created node has the correct permissions.
at line 498
protected bool
putWithExpiresAt(string $key, mixed $value, int $expiresAt)
Store an item with an absolute expiration timestamp.
at line 522
protected array
getPayload(string $key)
Retrieve an item and expiry time from the cache by key.
at line 575
protected mixed
unserialize(string $value)
Unserialize the given value.
at line 593
protected array
emptyPayload()
Get a default empty payload for the cache.
at line 601
string
path(string $key)
Get the full path for the given cache key.
at line 611
protected int
expiration(int $seconds)
Get the expiration time based on the given seconds.
at line 621
protected string
expiresAtHeader(int $expiresAt)
Get the fixed-width expiration header for a cache item.
at line 629
bool
hasSeparateLockStore()
Determine if the lock store is separate from the cache store.