Sections

Class Phalcon\Cache

Source on GitHub

Namespace Phalcon
Uses Phalcon\Cache\Adapter\AdapterInterface, Phalcon\Cache\Exception\Exception, Phalcon\Cache\Exception\InvalidArgumentException, Psr\SimpleCache\CacheInterface, Traversable
Implements CacheInterface

This component offers caching capabilities for your application. Phalcon\Cache implements PSR-16.

Properties

/**
 * The adapter
 *
 * @var AdapterInterface
 */
protected adapter;

Methods

public function __construct( AdapterInterface $adapter ): void;

Constructor.

@param AdapterInterface adapter The cache adapter

public function clear(): bool;

Wipes clean the entire cache’s keys.

@return bool True on success and false on failure.

public function delete( mixed $key ): bool;

Delete an item from the cache by its unique key.

@param string $key The unique cache key of the item to delete.

@return bool True if the item was successfully removed. False if there was an error.

@throws Phalcon\Cache\Exception\InvalidArgumentException MUST be thrown if the $key string is not a legal value.

public function deleteMultiple( mixed $keys ): bool;

Deletes multiple cache items in a single operation.

@param iterable $keys A list of string-based keys to be deleted.

@return bool True if the items were successfully removed. False if there was an error.

@throws Phalcon\Cache\Exception\InvalidArgumentException MUST be thrown if $keys is neither an array nor a Traversable, or if any of the $keys are not a legal value.

public function get( mixed $key, mixed $defaultValue = null ): mixed;

Fetches a value from the cache.

@param string $key The unique key of this item in the cache. @param mixed $default Default value to return if the key does not exist.

@return mixed The value of the item from the cache, or $default in case of cache miss.

@throws Phalcon\Cache\Exception\InvalidArgumentException MUST be thrown if the $key string is not a legal value.

public function getAdapter(): AdapterInterface
public function getMultiple( mixed $keys, mixed $defaultValue = null ): mixed;

Obtains multiple cache items by their unique keys.

@param iterable $keys A list of keys that can obtained in a single operation. @param mixed $default Default value to return for keys that do not exist.

@return iterable A list of key => value pairs. Cache keys that do not exist or are stale will have $default as value.

@throws Phalcon\Cache\Exception\InvalidArgumentException MUST be thrown if $keys is neither an array nor a Traversable, or if any of the $keys are not a legal value.

public function has( mixed $key ): bool;

Determines whether an item is present in the cache.

@param string $key The cache item key.

@return bool

@throws Phalcon\Cache\Exception\InvalidArgumentException MUST be thrown if the $key string is not a legal value.

public function set( mixed $key, mixed $value, mixed $ttl = null ): bool;

Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time.

@param string $key The key of the item to store. @param mixed $value The value of the item to store. Must be serializable. @param null|int|\DateInterval $ttl Optional. The TTL value of this item. If no value is sent and the driver supports TTL then the library may set a default value for it or let the driver take care of that.

@return bool True on success and false on failure.

@throws Phalcon\Cache\Exception\InvalidArgumentException MUST be thrown if the $key string is not a legal value.

public function setMultiple( mixed $values, mixed $ttl = null ): bool;

Persists a set of key => value pairs in the cache, with an optional TTL.

@param iterable $values A list of key => value pairs for a multiple-set operation. @param null|int|\DateInterval $ttl Optional. The TTL value of this item. If no value is sent and the driver supports TTL then the library may set a default value for it or let the driver take care of that.

@return bool True on success and false on failure.

@throws Phalcon\Cache\Exception\InvalidArgumentException MUST be thrown if $values is neither an array nor a Traversable, or if any of the $values are not a legal value.

protected function checkKey( mixed $key ): void;

Checks the key. If it contains invalid characters an exception is thrown

protected function checkKeys( mixed $keys ): void;

Checks the key. If it contains invalid characters an exception is thrown

Interface Phalcon\Cache\Adapter\AdapterInterface

Source on GitHub

Namespace Phalcon\Cache\Adapter
Uses Phalcon\Storage\Adapter\AdapterInterface
Extends StorageAdapterInterface

Interface for Phalcon\Cache adapters

Class Phalcon\Cache\Adapter\Apcu

Source on GitHub

Namespace Phalcon\Cache\Adapter
Uses Phalcon\Cache\Adapter\AdapterInterface, Phalcon\Storage\Adapter\Apcu
Extends StorageApcu
Implements CacheAdapterInterface

Apcu adapter

Class Phalcon\Cache\Adapter\Libmemcached

Source on GitHub

Namespace Phalcon\Cache\Adapter
Uses Phalcon\Cache\Adapter\AdapterInterface, Phalcon\Storage\Adapter\Libmemcached
Extends StorageLibmemcached
Implements CacheAdapterInterface

Libmemcached adapter

Class Phalcon\Cache\Adapter\Memory

Source on GitHub

Namespace Phalcon\Cache\Adapter
Uses Phalcon\Cache\Adapter\AdapterInterface, Phalcon\Storage\Adapter\Memory
Extends StorageMemory
Implements CacheAdapterInterface

Memory adapter

Class Phalcon\Cache\Adapter\Redis

Source on GitHub

Namespace Phalcon\Cache\Adapter
Uses Phalcon\Cache\Adapter\AdapterInterface, Phalcon\Storage\Adapter\Redis
Extends StorageRedis
Implements CacheAdapterInterface

Redis adapter

Class Phalcon\Cache\Adapter\Stream

Source on GitHub

Namespace Phalcon\Cache\Adapter
Uses Phalcon\Cache\Adapter\AdapterInterface, Phalcon\Storage\Adapter\Stream
Extends StorageStream
Implements CacheAdapterInterface

Stream adapter

Class Phalcon\Cache\AdapterFactory

Source on GitHub

Namespace Phalcon\Cache
Uses Phalcon\Cache\Adapter\AbstractAdapter, Phalcon\Cache\Exception\Exception, Phalcon\Factory\AbstractFactory, Phalcon\Storage\SerializerFactory
Extends AbstractFactory

Factory to create Cache adapters

Properties

/**
 * @var SerializerFactory
 */
private serializerFactory;

Methods

public function __construct( SerializerFactory $factory = null, array $services = [] );

AdapterFactory constructor.

public function newInstance( string $name, array $options = [] ): AbstractAdapter;

Create a new instance of the adapter

protected function getAdapters(): array;

Returns the available adapters

Class Phalcon\Cache\CacheFactory

Source on GitHub

Namespace Phalcon\Cache
Uses Phalcon\Cache\Adapter\AdapterInterface, Phalcon\Cache\AdapterFactory, Phalcon\Cache, Phalcon\Cache\CacheInterface, Phalcon\Cache\Exception\Exception, Phalcon\Config, Phalcon\Factory\AbstractFactory, Phalcon\Helper\Arr

Creates a new Cache class

Properties

/**
 * @var AdapterFactory
 */
protected adapterFactory;

Methods

public function __construct( AdapterFactory $factory );

Constructor

public function load( mixed $config ): mixed;

Factory to create an instace from a Config object

public function newInstance( string $name, array $options = [] ): CacheInterface;

Constructs a new Cache instance.

Class Phalcon\Cache\Exception\Exception

Source on GitHub

Namespace Phalcon\Cache\Exception
Extends \Exception
Implements \Psr\SimpleCache\CacheException

Exceptions thrown in Phalcon\Cache will use this class

Class Phalcon\Cache\Exception\InvalidArgumentException

Source on GitHub

Namespace Phalcon\Cache\Exception
Extends \Exception
Implements \Psr\SimpleCache\InvalidArgumentException

Exceptions thrown in Phalcon\Cache will use this class