Skip to content

Phalcon Cache

Updated View as Markdown

Cache\AbstractCache

AbstractSource on GitHub

This 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).

Uses DateInterval · Phalcon\Cache\Adapter\AdapterInterface · Phalcon\Cache\Adapter\Redis · Phalcon\Events\EventsAwareInterface · Phalcon\Events\Traits\EventsAwareTrait · Redis · Throwable · Traversable

Method Summary

Properties

protectedAdapterInterface$adapter

Methods

Public · 4

__construct()

public function __construct( AdapterInterface $adapter );

Constructor.

get()

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

Fetches a value from the cache.

getAdapter()

public function getAdapter(): AdapterInterface;

Returns the current adapter

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.

Protected · 11

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.

getExceptionClass()

abstract protected function getExceptionClass(): string;

Returns the exception class that will be used for exceptions thrown

Cache\AdapterFactory

ClassSource on GitHub

Factory to create Cache adapters

Uses Phalcon\Cache\Adapter\AdapterInterface · Phalcon\Cache\Adapter\Apcu · Phalcon\Cache\Adapter\Libmemcached · Phalcon\Cache\Adapter\Memory · Phalcon\Cache\Adapter\Redis · Phalcon\Cache\Adapter\RedisCluster · Phalcon\Cache\Adapter\Stream · Phalcon\Cache\Adapter\Weak · Phalcon\Cache\Exception\Exception · Phalcon\Contracts\Storage\StorageTypes · Phalcon\Factory\AbstractFactory · Phalcon\Storage\SerializerFactory

Method Summary

Properties

protectedSerializerFactory$serializerFactory

Methods

Public · 2

__construct()

public function __construct(
    SerializerFactory $serializerFactory,
    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

InterfaceSource on GitHub

Interface for Phalcon\Cache adapters

Uses Phalcon\Storage\Adapter\AdapterInterface

Cache\Adapter\Apcu

ClassSource on GitHub

Apcu adapter

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

Properties

protectedstring$eventType = "cache"

EventType prefix.

Cache\Adapter\Libmemcached

ClassSource on GitHub

Libmemcached adapter

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

Properties

protectedstring$eventType = "cache"

EventType prefix.

Cache\Adapter\Memory

ClassSource on GitHub

Memory adapter

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

Properties

protectedstring$eventType = "cache"

EventType prefix.

Cache\Adapter\Redis

ClassSource on GitHub

Redis adapter

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

Properties

protectedstring$eventType = "cache"

EventType prefix.

Cache\Adapter\RedisCluster

ClassSource on GitHub

RedisCluster adapter

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

Properties

protectedstring$eventType = "cache"

EventType prefix.

Cache\Adapter\Stream

ClassSource on GitHub

Stream adapter

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

Properties

protectedstring$eventType = "cache"

EventType prefix.

Cache\Adapter\Weak

ClassSource on GitHub

WeakCache implementation based on WeakReference

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

Properties

protectedstring$eventType = "cache"

EventType prefix.

Cache\Cache

ClassSource on GitHub

This component offers caching capabilities for your application.

Uses DateInterval · Phalcon\Cache\Exception\InvalidArgumentException · Throwable

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
): mixed;

Fetches a value from the cache.

getMultiple()

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

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

ClassSource on GitHub

Creates a new Cache class

Uses Phalcon\Cache\Exception\Exception · Phalcon\Config\ConfigInterface · Phalcon\Contracts\Storage\StorageTypes · Phalcon\Factory\AbstractConfigFactory

Method Summary

Properties

protectedAdapterFactory$adapterFactory

Methods

Public · 3

__construct()

public function __construct( AdapterFactory $adapterFactory );

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;

Returns the exception class for the factory

Cache\CacheInterface

InterfaceSource on GitHub

Interface for Phalcon\Cache\Cache

The cache class carries this member and the framework calls it on the interface. It joins the contract in the next major; until then the tag below records what all implementations provide.

@method AdapterInterface getAdapter()

Uses Phalcon\Cache\Adapter\AdapterInterface · Phalcon\Contracts\Cache\Cache

Cache\Exception\Exception

ClassSource on GitHub

Exceptions thrown in Phalcon\Cache will use this class

  • \Exception
    • Phalcon\Cache\Exception\Exception

Cache\Exception\InvalidArgumentException

ClassSource on GitHub

Exceptions thrown in Phalcon\Cache for invalid arguments will use this class

  • \Exception
    • Phalcon\Cache\Exception\InvalidArgumentException
Navigation

Type to search…

↑↓ navigate↵ selectEsc close