DatabaseStore
class DatabaseStore implements CanFlushLocks, LockProvider, Store
Traits
Properties
| protected ConnectionResolverInterface | $resolver | The database connection resolver. |
|
| protected string|null | $connectionName | The connection name. |
|
| protected string|null | $lockConnectionName | The lock connection name. |
|
| protected string | $table | The name of the cache table. |
|
| protected string | $prefix | A string that should be prepended to keys. |
|
| protected string | $lockTable | The name of the cache locks table. |
|
| protected array | $lockLottery | An array representation of the lock lottery odds. |
|
| protected int | $defaultLockTimeoutInSeconds | The default number of seconds that a lock should be held. |
|
| 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.
Create a new database store.
Get a fresh connection from the pool.
Retrieve an item from the cache by key.
Retrieve multiple items from the cache by key.
Store an item in the cache for a given number of seconds.
Store multiple items in the cache for a given number of seconds.
Store an item in the cache if the key doesn't exist.
Increment the value of an item in the cache.
Decrement the value of an item in the cache.
Increment or decrement an item in the cache.
Get the current system time.
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 an item from the cache if it is expired.
Remove multiple items from the cache.
Remove all expired items from the given set from the cache.
Remove all items from the cache.
Determine if the store can currently flush locks.
Remove all locks from the store.
Remove all expired entries from the cache.
Get the underlying database connection.
Set the connection name for the cache store.
Get the connection used to manage locks.
Specify the connection that should be used to manage locks.
Get the cache key prefix.
Set the cache key prefix.
Serialize the given value.
Unserialize the given value.
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.
at line 79
__construct(ConnectionResolverInterface $resolver, string|null $connectionName, string $table, string $prefix = '', string $lockTable = 'cache_locks', array $lockLottery = [2, 100], int $defaultLockTimeoutInSeconds = 86400, array|bool|null $serializableClasses = null, SerializableClassPolicy|null $serializableClassPolicy = null)
Create a new database store.
at line 104
protected ConnectionInterface
connection()
Get a fresh connection from the pool.
at line 112
mixed
get(string $key)
Retrieve an item from the cache by key.
at line 122
array
many(array $keys)
Retrieve multiple items from the cache by key.
Items not found in the cache will have a null value.
at line 163
bool
put(string $key, mixed $value, int $seconds)
Store an item in the cache for a given number of seconds.
at line 171
bool
putMany(array $values, int $seconds)
Store multiple items in the cache for a given number of seconds.
at line 198
bool
add(string $key, mixed $value, int $seconds)
Store an item in the cache if the key doesn't exist.
at line 214
bool|int
increment(string $key, int $value = 1)
Increment the value of an item in the cache.
at line 224
bool|int
decrement(string $key, int $value = 1)
Decrement the value of an item in the cache.
at line 234
protected bool|int
incrementOrDecrement(string $key, int $value, Closure $callback)
Increment or decrement an item in the cache.
at line 276
protected int
getTime()
Get the current system time.
at line 284
bool
forever(string $key, mixed $value)
Store an item in the cache indefinitely.
at line 292
Lock
lock(string $name, int $seconds = 0, string|null $owner = null)
Get a lock instance.
at line 309
Lock
restoreLock(string $name, string $owner)
Restore a lock instance using the owner identifier.
at line 317
bool
touch(string $key, int $seconds)
Adjust the expiration time of a cached item.
at line 328
bool
forget(string $key)
Remove an item from the cache.
at line 336
bool
forgetIfExpired(string $key)
Remove an item from the cache if it is expired.
at line 344
protected bool
forgetMany(array $keys)
Remove multiple items from the cache.
at line 357
protected bool
forgetManyIfExpired(array $keys, bool $prefixed = false)
Remove all expired items from the given set from the cache.
at line 376
bool
flush()
Remove all items from the cache.
at line 386
bool
supportsFlushingLocks()
Determine if the store can currently flush locks.
at line 396
bool
flushLocks()
Remove all locks from the store.
at line 410
int
pruneExpired()
Remove all expired entries from the cache.
at line 420
protected Builder
table()
Get a query builder for the cache table.
at line 428
protected Builder
lockTable()
Get a query builder for the cache locks table.
at line 436
ConnectionInterface
getConnection()
Get the underlying database connection.
at line 447
DatabaseStore
setConnection(string $connectionName)
Set the connection name for the cache store.
Boot-only. Persists on the cached store for the worker lifetime; per-request use races across coroutines.
at line 457
ConnectionInterface
getLockConnection()
Get the connection used to manage locks.
at line 468
DatabaseStore
setLockConnection(string $connectionName)
Specify the connection that should be used to manage locks.
Boot-only. Persists on the cached store for the worker lifetime; per-request use races across coroutines.
at line 478
string
getPrefix()
Get the cache key prefix.
at line 489
void
setPrefix(string $prefix)
Set the cache key prefix.
Boot-only. Persists on the cached store for the worker lifetime; per-request use races across coroutines.
at line 497
protected string
serialize(mixed $value)
Serialize the given value.
at line 514
protected mixed
unserialize(string $value)
Unserialize the given value.
at line 537
bool
hasSeparateLockStore()
Determine if the lock store is separate from the cache store.