Skip to content

Phalcon cache

NOTE

All classes are prefixed with Phalcon

Cache\AbstractCache

Abstract Source on GitHub

This component offers caching capabilities for your application.

Uses DateInterval · Phalcon\Cache\Adapter\AdapterInterface · Phalcon\Cache\Adapter\Redis · Phalcon\Cache\Exception\CacheKeysNotIterable · Phalcon\Cache\Exception\InvalidArgumentException · Phalcon\Cache\Exception\InvalidCacheKey · Phalcon\Events\EventsAwareInterface · Phalcon\Events\ManagerInterface · Traversable

Method Summary

public __construct( AdapterInterface $adapter ) Constructor. public AdapterInterface getAdapter() Returns the current adapter public ManagerInterface|null getEventsManager() Get the event manager public void setEventsManager( ManagerInterface $eventsManager ) Sets the event manager protected void checkKey( string $key ) Checks the key. If it contains invalid characters an exception is thrown protected void checkKeys( mixed $keys ) Checks the key. If it contains invalid characters an exception is thrown protected bool doClear() Wipes clean the entire cache's keys. protected bool doDelete( string $key ) Delete an item from the cache by its unique key. protected bool doDeleteMultiple( mixed $keys ) Deletes multiple cache items in a single operation. protected mixed doGet(string $key,mixed $defaultValue = null) Fetches a value from the cache. protected array doGetMultiple(mixed $keys,mixed $defaultValue = null) Obtains multiple cache items by their unique keys. protected bool doHas( string $key ) Determines whether an item is present in the cache. protected bool doSet(string $key,mixed $value,mixed $ttl = null) Persists data in the cache, uniquely referenced by a key with an optional protected bool doSetMultiple(mixed $values,mixed $ttl = null) Persists a set of key => value pairs in the cache, with an optional TTL. protected void fire(string $eventName,mixed $keys) Trigger an event for the eventsManager. protected string getExceptionClass() Returns the exception class that will be used for exceptions thrown

Properties

protected AdapterInterface $adapter The adapter
protected ManagerInterface|null $eventsManager = null Event Manager

Methods

Public · 4

__construct()

public function __construct( AdapterInterface $adapter );

Constructor.

getAdapter()

public function getAdapter(): AdapterInterface;

Returns the current adapter

getEventsManager()

public function getEventsManager(): ManagerInterface|null;

Get the event manager

setEventsManager()

public function setEventsManager( ManagerInterface $eventsManager ): void;

Sets the event manager

Protected · 12

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

Class Source on GitHub

Factory to create Cache adapters

Uses Phalcon\Cache\Adapter\AdapterInterface · Phalcon\Cache\Exception\Exception · Phalcon\Factory\AbstractFactory · Phalcon\Storage\SerializerFactory

Method Summary

Properties

protected SerializerFactory $serializerFactory

Methods

Public · 2

__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

Protected · 2

getExceptionClass()

protected function getExceptionClass(): string;

getServices()

protected function getServices(): array;

Returns the available adapters

Cache\Adapter\AdapterInterface

Interface Source on GitHub

Interface for Phalcon\Cache adapters

Uses Phalcon\Storage\Adapter\AdapterInterface

Cache\Adapter\Apcu

Class Source on GitHub

Apcu adapter

Uses Phalcon\Cache\Adapter\AdapterInterface · Phalcon\Storage\Adapter\Apcu

Properties

protected string $eventType = "cache"

Cache\Adapter\Libmemcached

Class Source on GitHub

Libmemcached adapter

Uses Phalcon\Cache\Adapter\AdapterInterface · Phalcon\Storage\Adapter\Libmemcached

Properties

protected string $eventType = "cache"

Cache\Adapter\Memory

Class Source on GitHub

Memory adapter

Uses Phalcon\Cache\Adapter\AdapterInterface · Phalcon\Storage\Adapter\Memory

Properties

protected string $eventType = "cache"

Cache\Adapter\Redis

Class Source on GitHub

Redis adapter

Uses Phalcon\Cache\Adapter\AdapterInterface · Phalcon\Storage\Adapter\Redis

Properties

protected string $eventType = "cache"

Cache\Adapter\RedisCluster

Class Source on GitHub

RedisCluster adapter

Uses Phalcon\Cache\Adapter\AdapterInterface · Phalcon\Storage\Adapter\RedisCluster

Properties

protected string $eventType = "cache"

Cache\Adapter\Stream

Class Source on GitHub

Stream adapter

Uses Phalcon\Cache\Adapter\AdapterInterface · Phalcon\Storage\Adapter\Stream

Properties

protected string $eventType = "cache"

Cache\Adapter\Weak

Class Source on GitHub

WeakCache implementation based on WeakReference

Uses Phalcon\Cache\Adapter\AdapterInterface · Phalcon\Storage\Adapter\Weak

Properties

protected string $eventType = "cache"

Cache\Cache

Class Source on GitHub

This component offers caching capabilities for your application.

Uses DateInterval · Phalcon\Cache\Adapter\AdapterInterface · Phalcon\Cache\Exception\InvalidArgumentException

Method Summary

Methods

Public · 8

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.

Protected · 1

getExceptionClass()

protected function getExceptionClass(): string;

Returns the exception class that will be used for exceptions thrown

Cache\CacheFactory

Class Source on GitHub

Creates a new Cache class

Uses Phalcon\Cache\Adapter\AdapterInterface · Phalcon\Cache\Cache · Phalcon\Cache\Exception\Exception · Phalcon\Config\ConfigInterface · Phalcon\Factory\AbstractConfigFactory

Method Summary

Properties

protected AdapterFactory $adapterFactory

Methods

Public · 3

__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.

Protected · 1

getExceptionClass()

protected function getExceptionClass(): string;

Cache\CacheInterface

Interface Source on GitHub

Interface for Phalcon\Cache\Cache

  • Phalcon\Cache\CacheInterface

Uses DateInterval · Phalcon\Cache\Exception\InvalidArgumentException

Method Summary

Methods

Public · 8

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.

Cache\Exception\CacheKeysNotIterable

Class Source on GitHub

This file is part of the Phalcon Framework.

(c) Phalcon Team team@phalcon.io

For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.

Method Summary

Methods

Public · 1

__construct()

public function __construct();

Cache\Exception\Exception

Class Source on GitHub

Exceptions thrown in Phalcon\Cache will use this class

  • \Exception
    • Phalcon\Cache\Exception\Exception

Cache\Exception\InvalidArgumentException

Class Source on GitHub

Exceptions thrown in Phalcon\Cache will use this class

Cache\Exception\InvalidCacheKey

Class Source on GitHub

This file is part of the Phalcon Framework.

(c) Phalcon Team team@phalcon.io

For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.

Method Summary

Methods

Public · 1

__construct()

public function __construct();