<commit_before>﻿.. _zend.cache.storage.adapter:

Zend\\Cache\\Storage\\Adapter
=============================

.. _zend.cache.storage.adapter.intro:

Overview
--------

   Storage adapters are wrappers for real storage resources such as memory
   and the filesystem, using the well known adapter pattern.

   They come with tons of methods to read, write and modify stored items
   and to get information about stored items and the storage.

   All adapters implement the interface ``Zend\Cache\Storage\StorageInterface``
   and most extend ``Zend\Cache\Storage\Adapter\AbstractAdapter``, which comes with basic logic.

   Configuration is handled by either ``Zend\Cache\Storage\Adapter\AdapterOptions``,
   or an adapter-specific options class if it exists. You may pass the options
   instance to the class at instantiation or via the ``setOptions()`` method,
   or alternately pass an associative array of options in either place
   (internally, these are then passed to an options class instance).
   Alternately, you can pass either the options instance or associative array
   to the ``Zend\Cache\StorageFactory::factory`` method.

.. note::

   **Many methods throw exceptions**

   Because many caching operations throw an exception on error, you need to catch them manually or you can use the
   plug-in ``Zend\Cache\Storage\Plugin\ExceptionHandler`` with ``throw_exceptions`` set to ``false`` to automatically
   catch them. You can also define an ``exception_callback`` to log exceptions.

.. _zend.cache.storage.adapter.quick-start:

Quick Start
-----------

   Caching adapters can either be created from the provided ``Zend\Cache\StorageFactory`` factory, or by simply
   instantiating one of the ``Zend\Cache\Storage\Adapter\*`` classes.

   To make life easier, the ``Zend\Cache\StorageFactory`` comes with a ``factory`` method to create an adapter and
   create/add all requested plugins at once.

.. code-block:: php
   :linenos:

   use Zend\Cache\StorageFactory;

   // Via factory:
   $cache = StorageFactory::factory(array(
       'adapter' => 'apc',
       'plugins' => array(
           'exception_handler' => array('throw_exceptions' => false),
       ),
   ));

   // Alternately:
   $cache  = StorageFactory::adapterFactory('apc');
   $plugin = StorageFactory::pluginFactory('exception_handler', array(
       'throw_exceptions' => false,
   ));
   $cache->addPlugin($plugin);

   // Or manually:
   $cache  = new Zend\Cache\Storage\Adapter\Apc();
   $plugin = new Zend\Cache\Storage\Plugin\ExceptionHandler(array(
       'throw_exceptions' => false,
   ));
   $cache->addPlugin($plugin);


.. _zend.cache.storage.adapter.options:

Basic Configuration Options
---------------------------

.. _zend.cache.adapter.common.options:<commit_msg>Better Quick-Start example for zend.cache.storage.adapter<commit_after>﻿.. _zend.cache.storage.adapter:

Zend\\Cache\\Storage\\Adapter
=============================

.. _zend.cache.storage.adapter.intro:

Overview
--------

   Storage adapters are wrappers for real storage resources such as memory
   and the filesystem, using the well known adapter pattern.

   They come with tons of methods to read, write and modify stored items
   and to get information about stored items and the storage.

   All adapters implement the interface ``Zend\Cache\Storage\StorageInterface``
   and most extend ``Zend\Cache\Storage\Adapter\AbstractAdapter``, which comes with basic logic.

   Configuration is handled by either ``Zend\Cache\Storage\Adapter\AdapterOptions``,
   or an adapter-specific options class if it exists. You may pass the options
   instance to the class at instantiation or via the ``setOptions()`` method,
   or alternately pass an associative array of options in either place
   (internally, these are then passed to an options class instance).
   Alternately, you can pass either the options instance or associative array
   to the ``Zend\Cache\StorageFactory::factory`` method.

.. note::

   **Many methods throw exceptions**

   Because many caching operations throw an exception on error, you need to catch them manually or you can use the
   plug-in ``Zend\Cache\Storage\Plugin\ExceptionHandler`` with ``throw_exceptions`` set to ``false`` to automatically
   catch them. You can also define an ``exception_callback`` to log exceptions.

.. _zend.cache.storage.adapter.quick-start:

Quick Start
-----------

   Caching adapters can either be created from the provided ``Zend\Cache\StorageFactory`` factory, or by simply
   instantiating one of the ``Zend\Cache\Storage\Adapter\*`` classes.

   To make life easier, the ``Zend\Cache\StorageFactory`` comes with a ``factory`` method to create an adapter and
   create/add all requested plugins at once.

.. code-block:: php
   :linenos:

   use Zend\Cache\StorageFactory;

   // Via factory:
   $cache = StorageFactory::factory(array(
       'adapter' => array(
           'name'    => 'apc',
           'options' => array('ttl' => 3600),
       ),
       'plugins' => array(
           'exception_handler' => array('throw_exceptions' => false),
       ),
   ));

   // Alternately:
   $cache  = StorageFactory::adapterFactory('apc', array('ttl' => 3600));
   $plugin = StorageFactory::pluginFactory('exception_handler', array(
       'throw_exceptions' => false,
   ));
   $cache->addPlugin($plugin);

   // Or manually:
   $cache  = new Zend\Cache\Storage\Adapter\Apc();
   $cache->getOptions()->setTtl(3600);
   
   $plugin = new Zend\Cache\Storage\Plugin\ExceptionHandler();
   $plugin->getOptions()->setThrowExceptions(false);
   $cache->addPlugin($plugin);


.. _zend.cache.storage.adapter.options:

Basic Configuration Options
---------------------------

.. _zend.cache.adapter.common.options:
{'fraction_non_alphanumeric': 0.13049546406140963, 'fraction_numerical': 0.00209351011863224, 'mean_word_length': 3.5035349567949723, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6740193', 'n_tokens_mistral': 1579, 'n_tokens_neox': 1510, 'n_words': 530}