class PdoAdapter extends AbstractAdapter implements PruneableInterface

Traits

LoggerAwareTrait
An implementation of CacheInterface for PSR-6 CacheItemPoolInterface classes.

Properties

protected $maxIdLength

Methods

array|Traversable
doFetch(array $ids)

Fetches several cache items.

bool
doHave(string $id)

Confirms if the cache contains specified cache item.

bool
doClear(string $namespace)

Deletes all items in the pool.

bool
doDelete(array $ids)

Removes multiple items from the pool.

array|bool
doSave(array $values, int $lifetime)

Persists several cache items immediately.

hasItem($key)

{@inheritdoc}

clear()

{@inheritdoc}

deleteItem($key)

{@inheritdoc}

deleteItems(array $keys)

{@inheritdoc}

bool
enableVersioning(bool $enable = true)

Enables/disables versioning of items.

reset()

{@inheritdoc}

static mixed
unserialize(string $value) deprecated

Like the native unserialize() function but throws an exception if anything goes wrong.

static 
handleUnserializeCallback($class)

No description

get(string $key, callable $callback, float $beta = null, array $metadata = null)

{@inheritdoc}

bool
delete(string $key)

{@inheritdoc}

callable
setCallbackWrapper(callable|null $callbackWrapper)

Wraps the callback passed to ->get() in a callable.

__construct($connOrDsn, string $namespace = '', int $defaultLifetime = 0, array $options = array(), MarshallerInterface $marshaller = null)

You can either pass an existing database connection as PDO instance or a Doctrine DBAL Connection or a DSN string that will be used to lazy-connect to the database when the cache is actually used.

createSystemCache(string $namespace, int $defaultLifetime, string $version, string $directory, LoggerInterface $logger = null)

Returns an ApcuAdapter if supported, a PhpFilesAdapter otherwise.

static 
createConnection($dsn, array $options = array())

No description

getItem($key)

{@inheritdoc}

getItems(array $keys = array())

{@inheritdoc}

save(CacheItemInterface $item)

{@inheritdoc}

saveDeferred(CacheItemInterface $item)

{@inheritdoc}

commit()

{@inheritdoc}

__destruct()

No description

createTable()

Creates the table to store cache items which can be called once for setup.

from PdoTrait
prune()

{@inheritdoc}

from PdoTrait

Details

abstract protected array|Traversable doFetch(array $ids)

Fetches several cache items.

Parameters

array $ids The cache identifiers to fetch

Return Value

array|Traversable The corresponding values found in the cache

abstract protected bool doHave(string $id)

Confirms if the cache contains specified cache item.

Parameters

string $id The identifier for which to check existence

Return Value

bool True if item exists in the cache, false otherwise

abstract protected bool doClear(string $namespace)

Deletes all items in the pool.

Parameters

string $namespace The prefix used for all identifiers managed by this pool

Return Value

bool True if the pool was successfully cleared, false otherwise

abstract protected bool doDelete(array $ids)

Removes multiple items from the pool.

Parameters

array $ids An array of identifiers that should be removed from the pool

Return Value

bool True if the items were successfully removed, false otherwise

abstract protected array|bool doSave(array $values, int $lifetime)

Persists several cache items immediately.

Parameters

array $values The values to cache, indexed by their cache identifier
int $lifetime The lifetime of the cached values, 0 for persisting until manual cleaning

Return Value

array|bool The identifiers that failed to be cached or a boolean stating if caching succeeded or not

hasItem($key)

{@inheritdoc}

Parameters

$key

clear()

{@inheritdoc}

deleteItem($key)

{@inheritdoc}

Parameters

$key

deleteItems(array $keys)

{@inheritdoc}

Parameters

array $keys

bool enableVersioning(bool $enable = true)

Enables/disables versioning of items.

When versioning is enabled, clearing the cache is atomic and doesn't require listing existing keys to proceed, but old keys may need garbage collection and extra round-trips to the back-end are required.

Calling this method also clears the memoized namespace version and thus forces a resynchonization of it.

Parameters

bool $enable

Return Value

bool the previous state of versioning

reset()

{@inheritdoc}

static protected mixed unserialize(string $value) deprecated

deprecated since Symfony 4.2, use DefaultMarshaller instead.

Like the native unserialize() function but throws an exception if anything goes wrong.

Parameters

string $value

Return Value

mixed

Exceptions

Exception

static handleUnserializeCallback($class)

Parameters

$class

get(string $key, callable $callback, float $beta = null, array $metadata = null)

{@inheritdoc}

Parameters

string $key
callable $callback
float $beta
array $metadata

bool delete(string $key)

{@inheritdoc}

Parameters

string $key

Return Value

bool

callable setCallbackWrapper(callable|null $callbackWrapper)

Wraps the callback passed to ->get() in a callable.

Parameters

callable|null $callbackWrapper

Return Value

callable the previous callback wrapper

__construct($connOrDsn, string $namespace = '', int $defaultLifetime = 0, array $options = array(), MarshallerInterface $marshaller = null)

You can either pass an existing database connection as PDO instance or a Doctrine DBAL Connection or a DSN string that will be used to lazy-connect to the database when the cache is actually used.

When a Doctrine DBAL Connection is passed, the cache table is created automatically when possible. Otherwise, use the createTable() method.

List of available options: * db_table: The name of the table [default: cache_items] * db_id_col: The column where to store the cache id [default: item_id] * db_data_col: The column where to store the cache data [default: item_data] * db_lifetime_col: The column where to store the lifetime [default: item_lifetime] * db_time_col: The column where to store the timestamp [default: item_time] * db_username: The username when lazy-connect [default: ''] * db_password: The password when lazy-connect [default: ''] * db_connection_options: An array of driver-specific connection options [default: array()]

Parameters

$connOrDsn
string $namespace
int $defaultLifetime
array $options
MarshallerInterface $marshaller

Exceptions

InvalidArgumentException When first argument is not PDO nor Connection nor string
InvalidArgumentException When PDO error mode is not PDO::ERRMODE_EXCEPTION
InvalidArgumentException When namespace contains invalid characters

static AdapterInterface createSystemCache(string $namespace, int $defaultLifetime, string $version, string $directory, LoggerInterface $logger = null)

Returns an ApcuAdapter if supported, a PhpFilesAdapter otherwise.

Using ApcuAdapter makes system caches compatible with read-only filesystems.

Parameters

string $namespace
int $defaultLifetime
string $version
string $directory
LoggerInterface $logger

Return Value

AdapterInterface

static createConnection($dsn, array $options = array())

Parameters

$dsn
array $options

CacheItem getItem($key)

{@inheritdoc}

Parameters

$key

Return Value

CacheItem

Traversable|CacheItem[] getItems(array $keys = array())

{@inheritdoc}

Parameters

array $keys

Return Value

Traversable|CacheItem[]

save(CacheItemInterface $item)

{@inheritdoc}

Parameters

CacheItemInterface $item

saveDeferred(CacheItemInterface $item)

{@inheritdoc}

Parameters

CacheItemInterface $item

commit()

{@inheritdoc}

__destruct()

createTable()

Creates the table to store cache items which can be called once for setup.

Cache ID are saved in a column of maximum length 255. Cache data is saved in a BLOB.

Exceptions

PDOException When the table already exists
DBALException When the table already exists
DomainException When an unsupported PDO driver is used

prune()

{@inheritdoc}