Cache\AbstractCache
AbstractSource on GitHubThis component offers caching capabilities for your application.
Event layering: cache operations can emit cache:* events from two layers.
This facade fires cache:before*/cache:after* around each operation, and
the underlying Storage adapter (whose eventType is "cache") also fires
cache:before*/cache:after* for the same operation. If an events manager
is wired into both the facade and the adapter, a single call emits the event
twice (once from each object). Wire the manager into one layer only; the
facade is the supported source for cache-level events (it also emits the
multi-key cache:*Multiple events).
Phalcon\Cache\AbstractCache- implementsPhalcon\Cache\CacheInterface,Phalcon\Events\EventsAwareInterface
Uses DateInterval · Phalcon\Cache\Adapter\AdapterInterface · Phalcon\Cache\Adapter\Redis · Phalcon\Cache\Exception\InvalidArgumentException · Phalcon\Events\EventsAwareInterface · Phalcon\Events\ManagerInterface · Traversable
Method Summary
public__construct( AdapterInterface$adapter )Constructor.publicget(string$key,mixed$defaultValue = null)Fetches a value from the cache.publicAdapterInterfacegetAdapter()Returns the current adapterpublicManagerInterface|nullgetEventsManager()Get the event managerpublicboolset(string$key,mixed$value,mixed$ttl = null)Persists data in the cache, uniquely referenced by a key with anpublicvoidsetEventsManager( ManagerInterface$eventsManager )Sets the event managerprotectedvoidcheckKey( string$key )Checks the key. If it contains invalid characters an exception is thrownprotectedvoidcheckKeys( mixed$keys )Checks the key. If it contains invalid characters an exception is thrownprotectedbooldoClear()Wipes clean the entire cache's keys.protectedbooldoDelete( string$key )Delete an item from the cache by its unique key.protectedbooldoDeleteMultiple( mixed$keys )Deletes multiple cache items in a single operation.protectedmixeddoGet(string$key,mixed$defaultValue = null)Fetches a value from the cache.protectedarraydoGetMultiple(mixed$keys,mixed$defaultValue = null)Obtains multiple cache items by their unique keys.protectedbooldoHas( string$key )Determines whether an item is present in the cache.protectedbooldoSet(string$key,mixed$value,mixed$ttl = null)Persists data in the cache, uniquely referenced by a key with an optionalprotectedbooldoSetMultiple(mixed$values,mixed$ttl = null)Persists a set of key => value pairs in the cache, with an optional TTL.protectedvoidfire(string$eventName,mixed$keys)Trigger an event for the eventsManager.protectedstringgetExceptionClass()Returns the exception class that will be used for exceptions thrownProperties
protectedAdapterInterface$adapterThe adapterprotectedManagerInterface|null$eventsManager = nullEvent ManagerMethods
__construct()
public function __construct( AdapterInterface $adapter );Constructor.
get()
abstract public function get(
string $key,
mixed $defaultValue = null
);Fetches a value from the cache.
getAdapter()
public function getAdapter(): AdapterInterface;Returns the current adapter
getEventsManager()
public function getEventsManager(): ManagerInterface|null;Get the event manager
set()
abstract public function set(
string $key,
mixed $value,
mixed $ttl = null
): bool;Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time.
setEventsManager()
public function setEventsManager( ManagerInterface $eventsManager ): void;Sets the event manager
checkKey()
protected function checkKey( string $key ): void;Checks the key. If it contains invalid characters an exception is thrown
checkKeys()
protected function checkKeys( mixed $keys ): void;Checks the key. If it contains invalid characters an exception is thrown
doClear()
protected function doClear(): bool;Wipes clean the entire cache’s keys.
doDelete()
protected function doDelete( string $key ): bool;Delete an item from the cache by its unique key.
doDeleteMultiple()
protected function doDeleteMultiple( mixed $keys ): bool;Deletes multiple cache items in a single operation.
doGet()
protected function doGet(
string $key,
mixed $defaultValue = null
): mixed;Fetches a value from the cache.
doGetMultiple()
protected function doGetMultiple(
mixed $keys,
mixed $defaultValue = null
): array;Obtains multiple cache items by their unique keys.
doHas()
protected function doHas( string $key ): bool;Determines whether an item is present in the cache.
doSet()
protected function doSet(
string $key,
mixed $value,
mixed $ttl = null
): bool;Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time.
doSetMultiple()
protected function doSetMultiple(
mixed $values,
mixed $ttl = null
): bool;Persists a set of key => value pairs in the cache, with an optional TTL.
fire()
protected function fire(
string $eventName,
mixed $keys
): void;Trigger an event for the eventsManager.
getExceptionClass()
abstract protected function getExceptionClass(): string;Returns the exception class that will be used for exceptions thrown
Cache\AdapterFactory
ClassSource on GitHubFactory to create Cache adapters
Phalcon\Factory\AbstractConfigFactoryPhalcon\Factory\AbstractFactoryPhalcon\Cache\AdapterFactory
Uses Phalcon\Cache\Adapter\AdapterInterface · Phalcon\Cache\Exception\Exception · Phalcon\Factory\AbstractFactory · Phalcon\Storage\SerializerFactory
Method Summary
public__construct(SerializerFactory$factory,array$services = [])AdapterFactory constructor.publicAdapterInterfacenewInstance(string$name,array$options = [])Create a new instance of the adapterprotectedstringgetExceptionClass()protectedarraygetServices()Returns the available adaptersProperties
protectedSerializerFactory$serializerFactoryMethods
__construct()
public function __construct(
SerializerFactory $factory,
array $services = []
);AdapterFactory constructor.
newInstance()
public function newInstance(
string $name,
array $options = []
): AdapterInterface;Create a new instance of the adapter
getExceptionClass()
protected function getExceptionClass(): string;getServices()
protected function getServices(): array;Returns the available adapters
Cache\Adapter\AdapterInterface
InterfaceSource on GitHubInterface for Phalcon\Cache adapters
Phalcon\Storage\Adapter\AdapterInterfacePhalcon\Cache\Adapter\AdapterInterface
Uses Phalcon\Storage\Adapter\AdapterInterface
Cache\Adapter\Apcu
ClassSource on GitHubApcu adapter
Phalcon\Storage\Adapter\AbstractAdapterPhalcon\Storage\Adapter\ApcuPhalcon\Cache\Adapter\Apcu- implementsPhalcon\Cache\Adapter\AdapterInterface
Uses Phalcon\Cache\Adapter\AdapterInterface · Phalcon\Storage\Adapter\Apcu
Properties
protectedstring$eventType = "cache"Cache\Adapter\Libmemcached
ClassSource on GitHubLibmemcached adapter
Phalcon\Storage\Adapter\AbstractAdapterPhalcon\Storage\Adapter\LibmemcachedPhalcon\Cache\Adapter\Libmemcached- implementsPhalcon\Cache\Adapter\AdapterInterface
Uses Phalcon\Cache\Adapter\AdapterInterface · Phalcon\Storage\Adapter\Libmemcached
Properties
protectedstring$eventType = "cache"Cache\Adapter\Memory
ClassSource on GitHubMemory adapter
Phalcon\Storage\Adapter\AbstractAdapterPhalcon\Storage\Adapter\MemoryPhalcon\Cache\Adapter\Memory- implementsPhalcon\Cache\Adapter\AdapterInterface
Uses Phalcon\Cache\Adapter\AdapterInterface · Phalcon\Storage\Adapter\Memory
Properties
protectedstring$eventType = "cache"Cache\Adapter\Redis
ClassSource on GitHubRedis adapter
Phalcon\Storage\Adapter\AbstractAdapterPhalcon\Storage\Adapter\RedisPhalcon\Cache\Adapter\Redis- implementsPhalcon\Cache\Adapter\AdapterInterface
Uses Phalcon\Cache\Adapter\AdapterInterface · Phalcon\Storage\Adapter\Redis
Properties
protectedstring$eventType = "cache"Cache\Adapter\RedisCluster
ClassSource on GitHubRedisCluster adapter
Phalcon\Storage\Adapter\AbstractAdapterPhalcon\Storage\Adapter\RedisPhalcon\Storage\Adapter\RedisClusterPhalcon\Cache\Adapter\RedisCluster- implementsPhalcon\Cache\Adapter\AdapterInterface
Uses Phalcon\Cache\Adapter\AdapterInterface · Phalcon\Storage\Adapter\RedisCluster
Properties
protectedstring$eventType = "cache"Cache\Adapter\Stream
ClassSource on GitHubStream adapter
Phalcon\Storage\Adapter\AbstractAdapterPhalcon\Storage\Adapter\StreamPhalcon\Cache\Adapter\Stream- implementsPhalcon\Cache\Adapter\AdapterInterface
Uses Phalcon\Cache\Adapter\AdapterInterface · Phalcon\Storage\Adapter\Stream
Properties
protectedstring$eventType = "cache"Cache\Adapter\Weak
ClassSource on GitHubWeakCache implementation based on WeakReference
Phalcon\Storage\Adapter\AbstractAdapterPhalcon\Storage\Adapter\WeakPhalcon\Cache\Adapter\Weak- implementsPhalcon\Cache\Adapter\AdapterInterface
Uses Phalcon\Cache\Adapter\AdapterInterface · Phalcon\Storage\Adapter\Weak
Properties
protectedstring$eventType = "cache"Cache\Cache
ClassSource on GitHubThis component offers caching capabilities for your application.
Phalcon\Cache\AbstractCachePhalcon\Cache\Cache
Uses DateInterval · Phalcon\Cache\Adapter\AdapterInterface · Phalcon\Cache\Exception\InvalidArgumentException
Method Summary
publicboolclear()Wipes clean the entire cache's keys.publicbooldelete( string$key )Delete an item from the cache by its unique key.publicbooldeleteMultiple( mixed$keys )Deletes multiple cache items in a single operation.publicget(string$key,mixed$defaultValue = null)Fetches a value from the cache.publicgetMultiple(mixed$keys,mixed$defaultValue = null)Obtains multiple cache items by their unique keys.publicboolhas( string$key )Determines whether an item is present in the cache.publicboolset(string$key,mixed$value,mixed$ttl = null)Persists data in the cache, uniquely referenced by a key with an optionalpublicboolsetMultiple(mixed$values,mixed$ttl = null)Persists a set of key => value pairs in the cache, with an optional TTL.protectedstringgetExceptionClass()Returns the exception class that will be used for exceptions thrownMethods
clear()
public function clear(): bool;Wipes clean the entire cache’s keys.
delete()
public function delete( string $key ): bool;Delete an item from the cache by its unique key.
deleteMultiple()
public function deleteMultiple( mixed $keys ): bool;Deletes multiple cache items in a single operation.
get()
public function get(
string $key,
mixed $defaultValue = null
);Fetches a value from the cache.
getMultiple()
public function getMultiple(
mixed $keys,
mixed $defaultValue = null
);Obtains multiple cache items by their unique keys.
has()
public function has( string $key ): bool;Determines whether an item is present in the cache.
set()
public function set(
string $key,
mixed $value,
mixed $ttl = null
): bool;Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time.
setMultiple()
public function setMultiple(
mixed $values,
mixed $ttl = null
): bool;Persists a set of key => value pairs in the cache, with an optional TTL.
getExceptionClass()
protected function getExceptionClass(): string;Returns the exception class that will be used for exceptions thrown
Cache\CacheFactory
ClassSource on GitHubCreates a new Cache class
Phalcon\Factory\AbstractConfigFactoryPhalcon\Cache\CacheFactory
Uses Phalcon\Cache\Adapter\AdapterInterface · Phalcon\Cache\Cache · Phalcon\Cache\Exception\Exception · Phalcon\Config\ConfigInterface · Phalcon\Factory\AbstractConfigFactory
Method Summary
public__construct( AdapterFactory$factory )ConstructorpublicCacheInterfaceload( mixed$config )Factory to create an instance from a Config objectpublicCacheInterfacenewInstance(string$name,array$options = [])Constructs a new Cache instance.protectedstringgetExceptionClass()Properties
protectedAdapterFactory$adapterFactoryMethods
__construct()
public function __construct( AdapterFactory $factory );Constructor
load()
public function load( mixed $config ): CacheInterface;Factory to create an instance from a Config object
newInstance()
public function newInstance(
string $name,
array $options = []
): CacheInterface;Constructs a new Cache instance.
getExceptionClass()
protected function getExceptionClass(): string;Cache\CacheInterface
InterfaceSource on GitHubInterface for Phalcon\Cache\Cache
Phalcon\Contracts\Cache\CachePhalcon\Cache\CacheInterface
Uses Phalcon\Contracts\Cache\Cache
Cache\Exception\Exception
ClassSource on GitHubExceptions thrown in Phalcon\Cache will use this class
\ExceptionPhalcon\Cache\Exception\Exception
Cache\Exception\InvalidArgumentException
ClassSource on GitHubExceptions thrown in Phalcon\Cache will use this class
\ExceptionPhalcon\Cache\Exception\InvalidArgumentException