GitHub Project

layout: default language: 'zh-cn' version: '4.0' title: 'Phalcon\Storage'

Abstract Class Phalcon\Storage\Adapter\AbstractAdapter

Source on GitHub

| Namespace | Phalcon\Storage\Adapter | | Uses | DateInterval, DateTime, Phalcon\Helper\Arr, Phalcon\Helper\Str, Phalcon\Storage\Exception, Phalcon\Storage\SerializerFactory, Phalcon\Storage\Serializer\SerializerInterface | | Implements | AdapterInterface |

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.

Properties

/**
 * @var mixed
 */
protected adapter;

/**
 * Name of the default serializer class
 *
 * @var string
 */
protected defaultSerializer = Php;

/**
 * Name of the default TTL (time to live)
 *
 * @var int
 */
protected lifetime = 3600;

/**
 * @var string
 */
protected prefix = ;

/**
 * Serializer
 *
 * @var SerializerInterface
 */
protected serializer;

/**
 * Serializer Factory
 *
 * @var SerializerFactory
 */
protected serializerFactory;

Methods

protected function __construct( SerializerFactory $factory, array $options = [] );

Sets parameters based on options

abstract public function clear(): bool;

Flushes/clears the cache

abstract public function decrement( string $key, int $value = int ): int | bool;

Decrements a stored number

abstract public function delete( string $key ): bool;

Deletes data from the adapter

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

Reads data from the adapter

abstract public function getAdapter(): mixed;

Returns the adapter - connects to the storage if not connected

public function getDefaultSerializer(): string
abstract public function getKeys( string $prefix = string ): array;

Returns all the keys stored

public function getPrefix(): string
abstract public function has( string $key ): bool;

Checks if an element exists in the cache

abstract public function increment( string $key, int $value = int ): int | bool;

Increments a stored number

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

Stores data in the adapter

public function setDefaultSerializer( string $defaultSerializer )
protected function getFilteredKeys( mixed $keys, string $prefix ): array;

Filters the keys array based on global and passed prefix

@return array

protected function getPrefixedKey( mixed $key ): string;

Returns the key requested, prefixed

protected function getSerializedData( mixed $content ): mixed;

Returns serialized data

protected function getTtl( mixed $ttl ): int;

Calculates the TTL for a cache item

@return int @throws Exception

protected function getUnserializedData( mixed $content, mixed $defaultValue = null ): mixed;

Returns unserialized data

protected function initSerializer(): void;

Initializes the serializer

Interface Phalcon\Storage\Adapter\AdapterInterface

Source on GitHub

| Namespace | Phalcon\Storage\Adapter | | Uses | Phalcon\Storage\Serializer\SerializerInterface |

Interface for Phalcon\Logger adapters

Methods

public function clear(): bool;

Flushes/clears the cache

public function decrement( string $key, int $value = int ): int | bool;

Decrements a stored number

public function delete( string $key ): bool;

Deletes data from the adapter

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

Reads data from the adapter

public function getAdapter(): mixed;

Returns the already connected adapter or connects to the backend server(s)

public function getKeys( string $prefix = string ): array;

Returns all the keys stored

public function getPrefix(): string;

Returns the prefix for the keys

public function has( string $key ): bool;

Checks if an element exists in the cache

public function increment( string $key, int $value = int ): int | bool;

Increments a stored number

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

Stores data in the adapter

Class Phalcon\Storage\Adapter\Apcu

Source on GitHub

| Namespace | Phalcon\Storage\Adapter | | Uses | APCuIterator, Phalcon\Helper\Arr, Phalcon\Storage\Exception, Phalcon\Storage\SerializerFactory, Phalcon\Storage\Serializer\SerializerInterface | | Extends | AbstractAdapter |

Apcu adapter

Properties

/**
 * @var array
 */
protected options;

Methods

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

Constructor

public function clear(): bool;

Flushes/clears the cache

public function decrement( string $key, int $value = int ): int | bool;

Decrements a stored number

@return bool|int

public function delete( string $key ): bool;

Reads data from the adapter

@return bool

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

Reads data from the adapter

@return mixed

public function getAdapter(): mixed;

Always returns null

@return null

public function getKeys( string $prefix = string ): array;

Stores data in the adapter

@return array

public function has( string $key ): bool;

Checks if an element exists in the cache

@return bool

public function increment( string $key, int $value = int ): int | bool;

Increments a stored number

@return bool|int

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

Stores data in the adapter

@return bool @throws \Exception

Class Phalcon\Storage\Adapter\Libmemcached

Source on GitHub

| Namespace | Phalcon\Storage\Adapter | | Uses | Phalcon\Helper\Arr, Phalcon\Storage\Exception, Phalcon\Storage\SerializerFactory, Phalcon\Storage\Serializer\SerializerInterface | | Extends | AbstractAdapter |

Libmemcached adapter

Properties

/**
 * @var array
 */
protected options;

Methods

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

Libmemcached constructor.

public function clear(): bool;

Flushes/clears the cache

@return bool @throws Exception

public function decrement( string $key, int $value = int ): int | bool;

Decrements a stored number

public function delete( string $key ): bool;

Reads data from the adapter

@return bool @throws Exception

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

Reads data from the adapter

@return mixed @throws Exception

public function getAdapter(): mixed;

Returns the already connected adapter or connects to the Memcached server(s)

@return \Memcached @throws Exception

public function getKeys( string $prefix = string ): array;

Stores data in the adapter

@return array

public function has( string $key ): bool;

Checks if an element exists in the cache

@return bool @throws Exception

public function increment( string $key, int $value = int ): int | bool;

Increments a stored number

@return bool|int @throws Exception

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

Stores data in the adapter

@return bool @throws Exception

Class Phalcon\Storage\Adapter\Memory

Source on GitHub

| Namespace | Phalcon\Storage\Adapter | | Uses | Phalcon\Collection, Phalcon\Helper\Arr, Phalcon\Storage\Exception, Phalcon\Storage\SerializerFactory, Phalcon\Storage\Serializer\SerializerInterface | | Extends | AbstractAdapter |

Memory adapter

Properties

/**
 * @var Collection
 */
protected data;

/**
 * @var array
 */
protected options;

Methods

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

Constructor

public function clear(): bool;

Flushes/clears the cache

public function decrement( string $key, int $value = int ): int | bool;

Decrements a stored number

@return bool|int

public function delete( string $key ): bool;

Reads data from the adapter

@return bool

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

Reads data from the adapter

@return mixed

public function getAdapter(): mixed;

Always returns null

@return null

public function getKeys( string $prefix = string ): array;

Stores data in the adapter

@return array

public function has( string $key ): bool;

Checks if an element exists in the cache

@return bool

public function increment( string $key, int $value = int ): int | bool;

Increments a stored number

@return bool|int

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

Stores data in the adapter

@return bool

Class Phalcon\Storage\Adapter\Redis

Source on GitHub

| Namespace | Phalcon\Storage\Adapter | | Uses | Phalcon\Helper\Arr, Phalcon\Storage\Exception, Phalcon\Storage\SerializerFactory, Phalcon\Storage\Serializer\SerializerInterface | | Extends | AbstractAdapter |

Redis adapter

Properties

/**
 * @var array
 */
protected options;

Methods

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

Constructor

public function clear(): bool;

Flushes/clears the cache

@return bool @throws Exception

public function decrement( string $key, int $value = int ): int | bool;

Decrements a stored number

@return bool|int @throws Exception

public function delete( string $key ): bool;

Reads data from the adapter

@return bool @throws Exception

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

Reads data from the adapter

@return mixed @throws Exception

public function getAdapter(): mixed;

Returns the already connected adapter or connects to the Redis server(s)

@return mixed|\Redis @throws Exception

public function getKeys( string $prefix = string ): array;

Stores data in the adapter

@return array @throws Exception

public function has( string $key ): bool;

Checks if an element exists in the cache

@return bool @throws Exception

public function increment( string $key, int $value = int ): int | bool;

Increments a stored number

@return bool|int @throws Exception

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

Stores data in the adapter

@return bool @throws Exception

Class Phalcon\Storage\Adapter\Stream

Source on GitHub

| Namespace | Phalcon\Storage\Adapter | | Uses | FilesystemIterator, Iterator, Phalcon\Helper\Arr, Phalcon\Helper\Str, Phalcon\Storage\Exception, Phalcon\Storage\SerializerFactory, Phalcon\Storage\Serializer\SerializerInterface, RecursiveDirectoryIterator, RecursiveIteratorIterator | | Extends | AbstractAdapter |

Stream adapter

Properties

/**
    * @var string
    */
protected storageDir = ;

/**
 * @var array
 */
protected options;

Methods

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

Stream constructor.

@throws Exception

public function clear(): bool;

Flushes/clears the cache

public function decrement( string $key, int $value = int ): int | bool;

Decrements a stored number

@return bool|int @throws \Exception

public function delete( string $key ): bool;

Reads data from the adapter

@return bool

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

Reads data from the adapter

@return mixed|null

public function getAdapter(): mixed;

Always returns null

@return null

public function getKeys( string $prefix = string ): array;

Stores data in the adapter

public function has( string $key ): bool;

Checks if an element exists in the cache and is not expired

@return bool

public function increment( string $key, int $value = int ): int | bool;

Increments a stored number

@return bool|int @throws \Exception

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

Stores data in the adapter

@return bool @throws \Exception

Class Phalcon\Storage\AdapterFactory

Source on GitHub

| Namespace | Phalcon\Storage | | Uses | Phalcon\Factory\AbstractFactory, Phalcon\Storage\Adapter\AdapterInterface | | Extends | AbstractFactory |

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.

Properties

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

Methods

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

AdapterFactory constructor.

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

Create a new instance of the adapter

protected function getAdapters(): array;

//

Class Phalcon\Storage\Exception

Source on GitHub

| Namespace | Phalcon\Storage | | Extends | \Phalcon\Exception |

Phalcon\Storage\Exception

Exceptions thrown in Phalcon\Storage will use this class

Abstract Class Phalcon\Storage\Serializer\AbstractSerializer

Source on GitHub

| Namespace | Phalcon\Storage\Serializer | | Uses | Phalcon\Storage\Exception | | Implements | SerializerInterface |

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.

Properties

/**
 * @var mixed
 */
protected data;

Methods

public function __construct( mixed $data = null );
Constructor
public function getData(): mixed;

@return mixed

public function setData( mixed $data ): void;
protected function isSerializable( mixed $data ): bool;

If this returns true, then the data returns back as is

Class Phalcon\Storage\Serializer\Base64

Source on GitHub

| Namespace | Phalcon\Storage\Serializer | | Uses | InvalidArgumentException | | Extends | AbstractSerializer |

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.

Methods

public function serialize(): string;
Serializes data
public function unserialize( mixed $data ): void;
Unserializes data

Class Phalcon\Storage\Serializer\Igbinary

Source on GitHub

| Namespace | Phalcon\Storage\Serializer | | Extends | AbstractSerializer |

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.

Methods

public function serialize(): string;
Serializes data
public function unserialize( mixed $data ): void;
Unserializes data

Class Phalcon\Storage\Serializer\Json

Source on GitHub

| Namespace | Phalcon\Storage\Serializer | | Uses | InvalidArgumentException, JsonSerializable, Phalcon\Helper\Json | | Extends | AbstractSerializer |

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.

Methods

public function serialize(): string;
Serializes data
public function unserialize( mixed $data ): void;
Unserializes data

Class Phalcon\Storage\Serializer\Msgpack

Source on GitHub

| Namespace | Phalcon\Storage\Serializer | | Extends | AbstractSerializer |

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.

Methods

public function serialize(): string | null;
Serializes data
public function unserialize( mixed $data ): void;
Unserializes data

Class Phalcon\Storage\Serializer\None

Source on GitHub

| Namespace | Phalcon\Storage\Serializer | | Uses | InvalidArgumentException | | Extends | AbstractSerializer |

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.

Methods

public function serialize(): string;
Serializes data
public function unserialize( mixed $data ): void;
Unserializes data

Class Phalcon\Storage\Serializer\Php

Source on GitHub

| Namespace | Phalcon\Storage\Serializer | | Uses | InvalidArgumentException, Phalcon\Storage\Exception | | Extends | AbstractSerializer |

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.

Methods

public function serialize(): string;
Serializes data
public function unserialize( mixed $data ): void;
Unserializes data

Interface Phalcon\Storage\Serializer\SerializerInterface

Source on GitHub

| Namespace | Phalcon\Storage\Serializer | | Uses | Serializable | | Extends | Serializable |

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.

Methods

public function getData(): mixed;

@return mixed

public function setData( mixed $data ): void;

Class Phalcon\Storage\SerializerFactory

Source on GitHub

| Namespace | Phalcon\Storage | | Uses | Phalcon\Factory\AbstractFactory, Phalcon\Storage\Serializer\SerializerInterface | | Extends | AbstractFactory |

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.

Methods

public function __construct( array $services = [] );

SerializerFactory constructor.

public function newInstance( string $name ): SerializerInterface;

@return SerializerInterface @throws Exception

protected function getAdapters(): array;

//