MemoryRepository
extends Repository
in package
Provides a simple request-level cache.
Tags
Table of Contents
- $cache : array<string|int, mixed>
- Values stored in memory
- $default : float|int
- The default number of minutes to store items.
- $events : Dispatcher
- The event dispatcher implementation.
- $macros : array<string|int, mixed>
- The registered string macros.
- $store : Store
- The cache store implementation.
- __call() : mixed
- Dynamically handle calls to the class.
- __callStatic() : mixed
- Dynamically handle calls to the class.
- __clone() : void
- Clone cache repository instance.
- __construct() : void
- Create a new cache repository instance.
- add() : bool
- Store an item in the cache if the key does not exist.
- clear() : mixed
- {@inheritdoc}
- decrement() : int|bool
- Decrement the value of an item in the cache.
- delete() : mixed
- {@inheritdoc}
- deleteMultiple() : mixed
- {@inheritdoc}
- flush() : bool
- Remove all items from the cache.
- flushInternalCache() : mixed
- Flushes the memory cache.
- forever() : void
- Store an item in the cache indefinitely.
- forget() : bool
- Remove an item from the cache.
- get() : mixed
- Retrieve an item from the cache by key.
- getDefaultCacheTime() : float|int
- Get the default cache time.
- getFromMemoryCache() : mixed
- Retrieve an item from the internal memory cache without trying the external driver.
- getMultiple() : mixed
- {@inheritdoc}
- getPrefix() : string
- Get the cache key prefix.
- getStore() : Store
- Get the cache store implementation.
- has() : bool
- Determine if an item exists in the cache.
- hasMacro() : bool
- Checks if macro is registered.
- increment() : int|bool
- Increment the value of an item in the cache.
- macro() : void
- Register a custom macro.
- many() : array<string|int, mixed>
- Retrieve multiple items from the cache by key.
- mixin() : void
- Mix another object into the class.
- offsetExists() : bool
- Determine if a cached value exists.
- offsetGet() : mixed
- Retrieve an item from the cache by key.
- offsetSet() : void
- Store an item in the cache for the default time.
- offsetUnset() : void
- Remove an item from the cache.
- pull() : mixed
- Retrieve an item from the cache and delete it.
- put() : void
- Store an item in the cache.
- putInMemoryCache() : mixed
- Puts an item in the memory cache, but not in the external cache.
- putMany() : void
- Store multiple items in the cache for a given number of minutes.
- remember() : mixed
- Get an item from the cache, or store the default value.
- rememberForever() : mixed
- Get an item from the cache, or store the default value forever.
- sear() : mixed
- Get an item from the cache, or store the default value forever.
- set() : mixed
- {@inheritdoc}
- setDefaultCacheTime() : $this
- Set the default cache time in minutes.
- setEventDispatcher() : void
- Set the event dispatcher instance.
- setMultiple() : mixed
- {@inheritdoc}
- tags() : TaggedCache
- Begin executing a new tags operation if the store supports it.
- availableAt() : int
- Get the "available at" UNIX timestamp.
- currentTime() : int
- Get the current system time as a UNIX timestamp.
- event() : void
- Fire an event for this cache instance.
- getMinutes() : float|int|null
- Calculate the number of minutes with the given duration.
- handleManyResult() : mixed
- Handle a result for the "many" method.
- itemKey() : string
- Format the key for a cache item.
- parseDateInterval() : DateTimeInterface|int
- If the given value is an interval, convert it to a DateTime instance.
- secondsUntil() : int
- Get the number of seconds until the given DateTime.
Properties
$cache
Values stored in memory
protected
array<string|int, mixed>
$cache
= []
$default
The default number of minutes to store items.
protected
float|int
$default
= 60
$events
The event dispatcher implementation.
protected
Dispatcher
$events
$macros
The registered string macros.
protected
static array<string|int, mixed>
$macros
= []
$store
The cache store implementation.
protected
Store
$store
Methods
__call()
Dynamically handle calls to the class.
public
__call(string $method, array<string|int, mixed> $parameters) : mixed
Parameters
- $method : string
- $parameters : array<string|int, mixed>
Tags
Return values
mixed —__callStatic()
Dynamically handle calls to the class.
public
static __callStatic(string $method, array<string|int, mixed> $parameters) : mixed
Parameters
- $method : string
- $parameters : array<string|int, mixed>
Tags
Return values
mixed —__clone()
Clone cache repository instance.
public
__clone() : void
Return values
void —__construct()
Create a new cache repository instance.
public
__construct(Store $store) : void
Parameters
- $store : Store
Return values
void —add()
Store an item in the cache if the key does not exist.
public
add(string $key, mixed $value, DateTimeInterface|DateInterval|float|int $minutes) : bool
Parameters
- $key : string
- $value : mixed
- $minutes : DateTimeInterface|DateInterval|float|int
Return values
bool —clear()
{@inheritdoc}
public
clear() : mixed
Return values
mixed —decrement()
Decrement the value of an item in the cache.
public
decrement(string $key[, mixed $value = 1 ]) : int|bool
Parameters
- $key : string
- $value : mixed = 1
Return values
int|bool —delete()
{@inheritdoc}
public
delete(mixed $key) : mixed
Parameters
- $key : mixed
Return values
mixed —deleteMultiple()
{@inheritdoc}
public
deleteMultiple(mixed $keys) : mixed
Parameters
- $keys : mixed
Return values
mixed —flush()
Remove all items from the cache.
public
flush() : bool
Return values
bool —flushInternalCache()
Flushes the memory cache.
public
flushInternalCache() : mixed
Calling this directly is generally only useful in testing. Use flush() otherwise.
Return values
mixed —forever()
Store an item in the cache indefinitely.
public
forever(string $key, mixed $value) : void
Parameters
- $key : string
- $value : mixed
Return values
void —forget()
Remove an item from the cache.
public
forget(string $key) : bool
Parameters
- $key : string
Return values
bool —get()
Retrieve an item from the cache by key.
public
get(string|array<string|int, mixed> $key[, mixed $default = null ]) : mixed
Parameters
- $key : string|array<string|int, mixed>
- $default : mixed = null
Return values
mixed —getDefaultCacheTime()
Get the default cache time.
public
getDefaultCacheTime() : float|int
Return values
float|int —getFromMemoryCache()
Retrieve an item from the internal memory cache without trying the external driver.
public
getFromMemoryCache( $key) : mixed
Used in testing
Parameters
Return values
mixed —getMultiple()
{@inheritdoc}
public
getMultiple(mixed $keys[, mixed $default = null ]) : mixed
Parameters
- $keys : mixed
- $default : mixed = null
Return values
mixed —getPrefix()
Get the cache key prefix.
public
getPrefix() : string
Return values
string —getStore()
Get the cache store implementation.
public
getStore() : Store
Return values
Store —has()
Determine if an item exists in the cache.
public
has(string $key) : bool
Parameters
- $key : string
Return values
bool —hasMacro()
Checks if macro is registered.
public
static hasMacro(string $name) : bool
Parameters
- $name : string
Return values
bool —increment()
Increment the value of an item in the cache.
public
increment(string $key[, mixed $value = 1 ]) : int|bool
Parameters
- $key : string
- $value : mixed = 1
Return values
int|bool —macro()
Register a custom macro.
public
static macro(string $name, object|callable $macro) : void
Parameters
- $name : string
- $macro : object|callable
Return values
void —many()
Retrieve multiple items from the cache by key.
public
many(array<string|int, mixed> $keys) : array<string|int, mixed>
Items not found in the cache will have a null value.
Parameters
- $keys : array<string|int, mixed>
Return values
array<string|int, mixed> —mixin()
Mix another object into the class.
public
static mixin(object $mixin) : void
Parameters
- $mixin : object
Return values
void —offsetExists()
Determine if a cached value exists.
public
offsetExists(string $key) : bool
Parameters
- $key : string
Return values
bool —offsetGet()
Retrieve an item from the cache by key.
public
offsetGet(string $key) : mixed
Parameters
- $key : string
Return values
mixed —offsetSet()
Store an item in the cache for the default time.
public
offsetSet(string $key, mixed $value) : void
Parameters
- $key : string
- $value : mixed
Return values
void —offsetUnset()
Remove an item from the cache.
public
offsetUnset(string $key) : void
Parameters
- $key : string
Return values
void —pull()
Retrieve an item from the cache and delete it.
public
pull(string $key[, mixed $default = null ]) : mixed
Parameters
- $key : string
- $default : mixed = null
Return values
mixed —put()
Store an item in the cache.
public
put(string $key, mixed $value[, DateTimeInterface|DateInterval|float|int $minutes = null ]) : void
Parameters
- $key : string
- $value : mixed
- $minutes : DateTimeInterface|DateInterval|float|int = null
Return values
void —putInMemoryCache()
Puts an item in the memory cache, but not in the external cache.
public
putInMemoryCache( $key, $value) : mixed
Used in testing
Parameters
Return values
mixed —putMany()
Store multiple items in the cache for a given number of minutes.
public
putMany(array<string|int, mixed> $values, DateTimeInterface|DateInterval|float|int $minutes) : void
Parameters
- $values : array<string|int, mixed>
- $minutes : DateTimeInterface|DateInterval|float|int
Return values
void —remember()
Get an item from the cache, or store the default value.
public
remember(string $key, DateTimeInterface|DateInterval|float|int $minutes, Closure $callback) : mixed
Parameters
- $key : string
- $minutes : DateTimeInterface|DateInterval|float|int
- $callback : Closure
Return values
mixed —rememberForever()
Get an item from the cache, or store the default value forever.
public
rememberForever(string $key, Closure $callback) : mixed
Parameters
- $key : string
- $callback : Closure
Return values
mixed —sear()
Get an item from the cache, or store the default value forever.
public
sear(string $key, Closure $callback) : mixed
Parameters
- $key : string
- $callback : Closure
Return values
mixed —set()
{@inheritdoc}
public
set(mixed $key, mixed $value[, mixed $ttl = null ]) : mixed
Parameters
- $key : mixed
- $value : mixed
- $ttl : mixed = null
Return values
mixed —setDefaultCacheTime()
Set the default cache time in minutes.
public
setDefaultCacheTime(float|int $minutes) : $this
Parameters
- $minutes : float|int
Return values
$this —setEventDispatcher()
Set the event dispatcher instance.
public
setEventDispatcher(Dispatcher $events) : void
Parameters
- $events : Dispatcher
Return values
void —setMultiple()
{@inheritdoc}
public
setMultiple(mixed $values[, mixed $ttl = null ]) : mixed
Parameters
- $values : mixed
- $ttl : mixed = null
Return values
mixed —tags()
Begin executing a new tags operation if the store supports it.
public
tags(array<string|int, mixed>|mixed $names) : TaggedCache
Parameters
- $names : array<string|int, mixed>|mixed
Tags
Return values
TaggedCache —availableAt()
Get the "available at" UNIX timestamp.
protected
availableAt(DateTimeInterface|DateInterval|int $delay) : int
Parameters
- $delay : DateTimeInterface|DateInterval|int
Return values
int —currentTime()
Get the current system time as a UNIX timestamp.
protected
currentTime() : int
Return values
int —event()
Fire an event for this cache instance.
protected
event(string $event) : void
Parameters
- $event : string
Return values
void —getMinutes()
Calculate the number of minutes with the given duration.
protected
getMinutes(DateTimeInterface|DateInterval|float|int $duration) : float|int|null
Parameters
- $duration : DateTimeInterface|DateInterval|float|int
Return values
float|int|null —handleManyResult()
Handle a result for the "many" method.
protected
handleManyResult(array<string|int, mixed> $keys, string $key, mixed $value) : mixed
Parameters
- $keys : array<string|int, mixed>
- $key : string
- $value : mixed
Return values
mixed —itemKey()
Format the key for a cache item.
protected
itemKey(string $key) : string
Parameters
- $key : string
Return values
string —parseDateInterval()
If the given value is an interval, convert it to a DateTime instance.
protected
parseDateInterval(DateTimeInterface|DateInterval|int $delay) : DateTimeInterface|int
Parameters
- $delay : DateTimeInterface|DateInterval|int
Return values
DateTimeInterface|int —secondsUntil()
Get the number of seconds until the given DateTime.
protected
secondsUntil(DateTimeInterface|DateInterval|int $delay) : int
Parameters
- $delay : DateTimeInterface|DateInterval|int