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.
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 41
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 57
protected int
currentTime()
Get the current system time as a UNIX timestamp.
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.
in
RetrievesMultipleKeys at line 21
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 40
bool
putMany(array $values, int $seconds)
Store multiple items in the cache for a given number of seconds.
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.
at line 77
mixed
get(string $key)
Retrieve an item from the cache by key.
at line 85
bool
put(string $key, mixed $value, int $seconds)
Store an item in the cache for a given number of seconds.
at line 107
bool
add(string $key, mixed $value, int $seconds)
Store an item in the cache if the key doesn't exist.
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.
at line 184
float|null
remainingSeconds(string $key)
Get the number of seconds until the given key expires.
at line 204
bool|int
increment(string $key, int $value = 1)
Increment the value of an item in the cache.
at line 216
bool|int
decrement(string $key, int $value = 1)
Decrement the value of an item in the cache.
at line 224
bool
forever(string $key, mixed $value)
Store an item in the cache indefinitely.
at line 232
Lock
lock(string $name, int $seconds = 0, string|null $owner = null)
Get a lock instance.
at line 253
Lock
restoreLock(string $name, string $owner)
Restore a lock instance using the owner identifier.
at line 261
bool
touch(string $key, int $seconds)
Adjust the expiration time of a cached item.
at line 275
bool
forget(string $key)
Remove an item from the cache.
at line 291
bool
flush()
Remove all items from the cache.
at line 311
bool
supportsFlushingLocks()
Determine if the store can currently flush locks.
at line 321
bool
flushLocks()
Remove all locks from the store.
at line 345
Filesystem
getFilesystem()
Get the Filesystem instance.
at line 353
string
getDirectory()
Get the working directory of the cache.
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.
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.
at line 387
string
getPrefix()
Get the cache key prefix.
at line 395
protected void
ensureCacheDirectoryExists(string $path)
Create the file cache directory if necessary.
at line 411
protected void
ensurePermissionsAreCorrect(string $path)
Ensure the created node has the correct permissions.
at line 424
protected array
getPayload(string $key)
Retrieve an item and expiry time from the cache by key.
at line 469
protected mixed
unserialize(string $value)
Unserialize the given value.
at line 485
protected array
emptyPayload()
Get a default empty payload for the cache.
at line 493
string
path(string $key)
Get the full path for the given cache key.
at line 503
protected int
expiration(int $seconds)
Get the expiration time based on the given seconds.
at line 513
protected string
expirationHeader(int $seconds)
Get the fixed-width expiration header for a cache item.
at line 521
bool
hasSeparateLockStore()
Determine if the lock store is separate from the cache store.