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.
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 23
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 42
bool
putMany(array $values, int $seconds)
Store multiple items in the cache for a given number of seconds.
at line 61
__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 78
mixed
get(string $key)
Retrieve an item from the cache by key.
at line 86
bool
put(string $key, mixed $value, int $seconds)
Store an item in the cache for a given number of seconds.
at line 94
bool
add(string $key, mixed $value, int $seconds)
Store an item in the cache if the key doesn't exist.
at line 128
bool
refreshIfOwned(string $key, string $expectedOwner, int $seconds)
Atomically refresh the expiration of a cache key if it matches the expected owner.
at line 171
float|null
remainingSeconds(string $key)
Get the number of seconds until the given key expires.
at line 193
bool|int
increment(string $key, int $value = 1)
Increment the value of an item in the cache.
at line 212
bool|int
decrement(string $key, int $value = 1)
Decrement the value of an item in the cache.
at line 220
bool
forever(string $key, mixed $value)
Store an item in the cache indefinitely.
at line 228
Lock
lock(string $name, int $seconds = 0, string|null $owner = null)
Get a lock instance.
at line 249
Lock
restoreLock(string $name, string $owner)
Restore a lock instance using the owner identifier.
at line 257
bool
touch(string $key, int $seconds)
Adjust the expiration time of a cached item.
at line 271
bool
forget(string $key)
Remove an item from the cache.
at line 287
bool
flush()
Remove all items from the cache.
at line 307
bool
supportsFlushingLocks()
Determine if the store can currently flush locks.
at line 317
bool
flushLocks()
Remove all locks from the store.
at line 341
Filesystem
getFilesystem()
Get the Filesystem instance.
at line 349
string
getDirectory()
Get the working directory of the cache.
at line 360
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.
at line 373
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.
at line 383
string
getPrefix()
Get the cache key prefix.
at line 391
protected void
ensureCacheDirectoryExists(string $path)
Create the file cache directory if necessary.
at line 407
protected void
ensurePermissionsAreCorrect(string $path)
Ensure the created node has the correct permissions.
at line 420
protected bool
putWithExpiresAt(string $key, mixed $value, int $expiresAt)
Store an item with an absolute expiration timestamp.
at line 444
protected array
getPayload(string $key)
Retrieve an item and expiry time from the cache by key.
at line 493
protected mixed
unserialize(string $value)
Unserialize the given value.
at line 511
protected array
emptyPayload()
Get a default empty payload for the cache.
at line 519
string
path(string $key)
Get the full path for the given cache key.
at line 529
protected int
expiration(int $seconds)
Get the expiration time based on the given seconds.
at line 539
protected string
expiresAtHeader(int $expiresAt)
Get the fixed-width expiration header for a cache item.
at line 547
bool
hasSeparateLockStore()
Determine if the lock store is separate from the cache store.