class TaggedCache extends Repository (View source)

Traits

Properties

static protected array $macros

The registered string macros.

from  Macroable
protected Store $store

The cache store implementation.

from  Repository
protected Dispatcher|null $events

The event dispatcher implementation.

from  Repository
protected int|null $default

The default number of seconds to store items.

from  Repository
protected array $config

The cache store configuration options.

from  Repository
protected TagSet $tags

The tag set instance.

Methods

int
secondsUntil(DateTimeInterface|DateInterval|int $delay)

Get the number of seconds until the given DateTime.

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

Get the "available at" UNIX timestamp.

parseDateInterval(DateTimeInterface|DateInterval|int $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.

static void
macro(string $name, object|callable $macro)

Register a custom macro.

static void
mixin(object $mixin, bool $replace = true)

Mix another object into the class.

static bool
hasMacro(string $name)

Checks if macro is registered.

static void
flushMacros()

Flush the existing macros.

static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
__call(string $method, array $parameters)

Dynamically handle calls to the class.

__construct(Store $store, TagSet $tags)

Create a new tagged cache instance.

bool
has(UnitEnum|array|string $key)

Determine if an item exists in the cache.

bool
missing(UnitEnum|string $key)

Determine if an item doesn't exist in the cache.

mixed
get(UnitEnum|array|string $key, mixed $default = null)

Retrieve an item from the cache by key.

array
many(array $keys)

Retrieve multiple items from the cache by key.

iterable
getMultiple($keys, $default = null)

{@inheritdoc}

mixed
handleManyResult(array $keys, string $key, mixed $value)

Handle a result for the "many" method.

TCacheValue)
pull(array|string $key, TCacheValue|TCacheValue $default = null)

Retrieve an item from the cache and delete it.

string
string(UnitEnum|string $key, Closure(): string|null|string|null $default = null)

Retrieve a string item from the cache.

int
integer(UnitEnum|string $key, Closure(): int|null|int|null $default = null)

Retrieve an integer item from the cache.

float
float(UnitEnum|string $key, Closure(): float|null|float|null $default = null)

Retrieve a float item from the cache.

bool
boolean(UnitEnum|string $key, Closure(): bool|null|bool|null $default = null)

Retrieve a boolean item from the cache.

array
array(UnitEnum|string $key, Closure(): array<array-key, mixed>|null|array<array-key, mixed>|null $default = null)

Retrieve an array item from the cache.

bool
put(string $key, mixed $value, DateTimeInterface|DateInterval|int|null $ttl = null)

Store an item in the cache.

bool
set(UnitEnum|array|string $key, mixed $value, DateTimeInterface|DateInterval|int|null $ttl = null)

Store an item in the cache.

bool
putMany(array $values, DateTimeInterface|DateInterval|int|null $ttl = null)

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

bool
putManyForever(array $values)

Store multiple items in the cache indefinitely.

bool
setMultiple($values, $ttl = null)

{@inheritdoc}

bool
add(string $key, mixed $value, DateTimeInterface|DateInterval|int|null $ttl = null)

Store an item in the cache if the key does not exist.

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

Increment the value of an item in the cache.

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

Decrement the value of an item in the cache.

bool
forever(string $key, mixed $value)

Store an item in the cache indefinitely.

TCacheValue
remember(string $key, DateTimeInterface|DateInterval|Closure|int|null $ttl, Closure $callback)

Get an item from the cache, or execute the given Closure and store the result.

TCacheValue
sear(string $key, Closure $callback)

Get an item from the cache, or execute the given Closure and store the result forever.

TCacheValue
rememberForever(string $key, Closure $callback)

Get an item from the cache, or execute the given Closure and store the result forever.

TCacheValue
flexible(UnitEnum|string $key, DateTimeInterface|DateInterval|DateTimeInterface|DateInterval|int} $ttl, TCacheValue $callback, array{seconds?: int, owner?: string}|null $lock = null, bool $alwaysDefer = false)

Retrieve an item from the cache by key, refreshing it in the background if it is stale.

TReturn
withoutOverlapping(UnitEnum|string $key, callable $callback, int $lockFor = 0, int $waitFor = 10, string|null $owner = null)

Execute a callback while holding an atomic lock on a cache mutex to prevent overlapping calls.

funnel(UnitEnum|string $name)

Funnel a callback for a maximum number of simultaneous executions.

bool
forget(string $key)

Remove an item from the cache.

bool
delete(UnitEnum|array|string $key)

Remove an item from the cache.

bool
deleteMultiple($keys)

{@inheritdoc}

bool
clear()

{@inheritdoc}

tags(mixed $names)

Begin executing a new tags operation if the store supports it.

string
itemKey(string $key)

Format the key for a cache item.

int
getSeconds(DateTimeInterface|DateInterval|int $ttl)

Calculate the number of seconds for the given TTL.

string|null
getName()

Get the name of the cache store.

bool
supportsTags()

Determine if the current store supports tags.

int|null
getDefaultCacheTime()

Get the default cache time.

$this
setDefaultCacheTime(int|null $seconds)

Set the default cache time in seconds.

getStore()

Get the cache store implementation.

setStore(Store $store)

Set the cache store implementation.

void
event(object|string $event)

Fire an event for this cache instance.

Dispatcher|null
getEventDispatcher()

Get the event dispatcher instance.

void
setEventDispatcher(Dispatcher $events)

Set the event dispatcher instance.

bool
offsetExists(UnitEnum|string $key)

Determine if a cached value exists.

mixed
offsetGet(UnitEnum|string $key)

Retrieve an item from the cache by key.

void
offsetSet(UnitEnum|string $key, mixed $value)

Store an item in the cache for the default time.

void
offsetUnset(UnitEnum|string $key)

Remove an item from the cache.

void
__clone()

Clone cache repository instance.

bool
flush()

Remove all items from the cache.

string
taggedItemKey(string $key)

Get a fully-qualified key for a tagged item.

getTags()

Get the tag set instance.

Details

protected int secondsUntil(DateTimeInterface|DateInterval|int $delay)

Get the number of seconds until the given DateTime.

Parameters

DateTimeInterface|DateInterval|int $delay

Return Value

int

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

Get the "available at" UNIX timestamp.

Parameters

DateTimeInterface|DateInterval|int $delay

Return Value

int

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

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

Parameters

DateTimeInterface|DateInterval|int $delay

Return Value

DateTimeInterface|int

protected int currentTime()

Get the current system time as a UNIX timestamp.

Return Value

int

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

static void macro(string $name, object|callable $macro)

Register a custom macro.

Parameters

string $name
object|callable $macro

Return Value

void

static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

static bool hasMacro(string $name)

Checks if macro is registered.

Parameters

string $name

Return Value

bool

static void flushMacros()

Flush the existing macros.

Return Value

void

static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

__construct(Store $store, TagSet $tags)

Create a new tagged cache instance.

Parameters

Store $store
TagSet $tags

bool has(UnitEnum|array|string $key)

Determine if an item exists in the cache.

Parameters

UnitEnum|array|string $key

Return Value

bool

bool missing(UnitEnum|string $key)

Determine if an item doesn't exist in the cache.

Parameters

UnitEnum|string $key

Return Value

bool

mixed get(UnitEnum|array|string $key, mixed $default = null)

Retrieve an item from the cache by key.

Parameters

UnitEnum|array|string $key
mixed $default

Return Value

mixed

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

iterable getMultiple($keys, $default = null)

{@inheritdoc}

Parameters

$keys
$default

Return Value

iterable

protected mixed handleManyResult(array $keys, string $key, mixed $value)

Handle a result for the "many" method.

Parameters

array $keys
string $key
mixed $value

Return Value

mixed

TCacheValue) pull(array|string $key, TCacheValue|TCacheValue $default = null)

Retrieve an item from the cache and delete it.

Parameters

array|string $key
TCacheValue|TCacheValue $default

Return Value

TCacheValue)

string string(UnitEnum|string $key, Closure(): string|null|string|null $default = null)

Retrieve a string item from the cache.

Parameters

UnitEnum|string $key
Closure(): string|null|string|null $default

Return Value

string

Exceptions

InvalidArgumentException

int integer(UnitEnum|string $key, Closure(): int|null|int|null $default = null)

Retrieve an integer item from the cache.

Parameters

UnitEnum|string $key
Closure(): int|null|int|null $default

Return Value

int

Exceptions

InvalidArgumentException

float float(UnitEnum|string $key, Closure(): float|null|float|null $default = null)

Retrieve a float item from the cache.

Parameters

UnitEnum|string $key
Closure(): float|null|float|null $default

Return Value

float

Exceptions

InvalidArgumentException

bool boolean(UnitEnum|string $key, Closure(): bool|null|bool|null $default = null)

Retrieve a boolean item from the cache.

Parameters

UnitEnum|string $key
Closure(): bool|null|bool|null $default

Return Value

bool

Exceptions

InvalidArgumentException

array array(UnitEnum|string $key, Closure(): array<array-key, mixed>|null|array<array-key, mixed>|null $default = null)

Retrieve an array item from the cache.

Parameters

UnitEnum|string $key
Closure(): array<array-key, mixed>|null|array<array-key, mixed>|null $default

Return Value

array

Exceptions

InvalidArgumentException

bool put(string $key, mixed $value, DateTimeInterface|DateInterval|int|null $ttl = null)

Store an item in the cache.

Parameters

string $key
mixed $value
DateTimeInterface|DateInterval|int|null $ttl

Return Value

bool

bool set(UnitEnum|array|string $key, mixed $value, DateTimeInterface|DateInterval|int|null $ttl = null)

Store an item in the cache.

Parameters

UnitEnum|array|string $key
mixed $value
DateTimeInterface|DateInterval|int|null $ttl

Return Value

bool

bool putMany(array $values, DateTimeInterface|DateInterval|int|null $ttl = null)

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

Parameters

array $values
DateTimeInterface|DateInterval|int|null $ttl

Return Value

bool

protected bool putManyForever(array $values)

Store multiple items in the cache indefinitely.

Parameters

array $values

Return Value

bool

bool setMultiple($values, $ttl = null)

{@inheritdoc}

Parameters

$values
$ttl

Return Value

bool

bool add(string $key, mixed $value, DateTimeInterface|DateInterval|int|null $ttl = null)

Store an item in the cache if the key does not exist.

Parameters

string $key
mixed $value
DateTimeInterface|DateInterval|int|null $ttl

Return Value

bool

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

Increment the value of an item in the cache.

Parameters

string $key
mixed $value

Return Value

int|bool

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

Decrement the value of an item in the cache.

Parameters

string $key
mixed $value

Return Value

int|bool

bool forever(string $key, mixed $value)

Store an item in the cache indefinitely.

Parameters

string $key
mixed $value

Return Value

bool

TCacheValue remember(string $key, DateTimeInterface|DateInterval|Closure|int|null $ttl, Closure $callback)

Get an item from the cache, or execute the given Closure and store the result.

Parameters

string $key
DateTimeInterface|DateInterval|Closure|int|null $ttl
Closure $callback

Return Value

TCacheValue

TCacheValue sear(string $key, Closure $callback)

Get an item from the cache, or execute the given Closure and store the result forever.

Parameters

string $key
Closure $callback

Return Value

TCacheValue

TCacheValue rememberForever(string $key, Closure $callback)

Get an item from the cache, or execute the given Closure and store the result forever.

Parameters

string $key
Closure $callback

Return Value

TCacheValue

TCacheValue flexible(UnitEnum|string $key, DateTimeInterface|DateInterval|DateTimeInterface|DateInterval|int} $ttl, TCacheValue $callback, array{seconds?: int, owner?: string}|null $lock = null, bool $alwaysDefer = false)

Retrieve an item from the cache by key, refreshing it in the background if it is stale.

Parameters

UnitEnum|string $key
DateTimeInterface|DateInterval|DateTimeInterface|DateInterval|int} $ttl
TCacheValue $callback
array{seconds?: int, owner?: string}|null $lock
bool $alwaysDefer

Return Value

TCacheValue

TReturn withoutOverlapping(UnitEnum|string $key, callable $callback, int $lockFor = 0, int $waitFor = 10, string|null $owner = null)

Execute a callback while holding an atomic lock on a cache mutex to prevent overlapping calls.

Parameters

UnitEnum|string $key
callable $callback
int $lockFor
int $waitFor
string|null $owner

Return Value

TReturn

Exceptions

LockTimeoutException

ConcurrencyLimiterBuilder funnel(UnitEnum|string $name)

Funnel a callback for a maximum number of simultaneous executions.

Parameters

UnitEnum|string $name

Return Value

ConcurrencyLimiterBuilder

bool forget(string $key)

Remove an item from the cache.

Parameters

string $key

Return Value

bool

bool delete(UnitEnum|array|string $key)

Remove an item from the cache.

Parameters

UnitEnum|array|string $key

Return Value

bool

bool deleteMultiple($keys)

{@inheritdoc}

Parameters

$keys

Return Value

bool

bool clear()

{@inheritdoc}

Return Value

bool

TaggedCache tags(mixed $names)

Begin executing a new tags operation if the store supports it.

Parameters

mixed $names

Return Value

TaggedCache

Exceptions

BadMethodCallException

protected string itemKey(string $key)

Format the key for a cache item.

Parameters

string $key

Return Value

string

protected int getSeconds(DateTimeInterface|DateInterval|int $ttl)

Calculate the number of seconds for the given TTL.

Parameters

DateTimeInterface|DateInterval|int $ttl

Return Value

int

string|null getName()

Get the name of the cache store.

Return Value

string|null

bool supportsTags()

Determine if the current store supports tags.

Return Value

bool

int|null getDefaultCacheTime()

Get the default cache time.

Return Value

int|null

$this setDefaultCacheTime(int|null $seconds)

Set the default cache time in seconds.

Parameters

int|null $seconds

Return Value

$this

Store getStore()

Get the cache store implementation.

Return Value

Store

Repository setStore(Store $store)

Set the cache store implementation.

Parameters

Store $store

Return Value

Repository

protected void event(object|string $event)

Fire an event for this cache instance.

Parameters

object|string $event

Return Value

void

Dispatcher|null getEventDispatcher()

Get the event dispatcher instance.

Return Value

Dispatcher|null

void setEventDispatcher(Dispatcher $events)

Set the event dispatcher instance.

Parameters

Dispatcher $events

Return Value

void

bool offsetExists(UnitEnum|string $key)

Determine if a cached value exists.

Parameters

UnitEnum|string $key

Return Value

bool

mixed offsetGet(UnitEnum|string $key)

Retrieve an item from the cache by key.

Parameters

UnitEnum|string $key

Return Value

mixed

void offsetSet(UnitEnum|string $key, mixed $value)

Store an item in the cache for the default time.

Parameters

UnitEnum|string $key
mixed $value

Return Value

void

void offsetUnset(UnitEnum|string $key)

Remove an item from the cache.

Parameters

UnitEnum|string $key

Return Value

void

void __clone()

Clone cache repository instance.

Return Value

void

bool flush()

Remove all items from the cache.

Return Value

bool

string taggedItemKey(string $key)

Get a fully-qualified key for a tagged item.

Parameters

string $key

Return Value

string

TagSet getTags()

Get the tag set instance.

Return Value

TagSet