Permalink
Browse files

Merge pull request #7 from doctrine/caching

initial docs for caching
  • Loading branch information...
2 parents 680221c + 3ed9521 commit cab44407803a07d619376f1337bf521813e9c565 @guilhermeblanco guilhermeblanco committed Sep 27, 2012
Showing with 52 additions and 0 deletions.
  1. +1 −0 en/index.rst
  2. +51 −0 en/reference/caching.rst
View
@@ -14,6 +14,7 @@ Contents:
reference/class-loading
reference/annotations
+ reference/caching
Indices and tables
==================
@@ -0,0 +1,51 @@
+Doctrine Caching
+=================
+
+The Doctrine Common caching library was born from a need in the
+`Doctrine2 ORM <http://www.doctrine-project.org/projects/orm>`_ to
+allow caching of result sets. The library is independent and can be
+used in your own libraries to caching.
+
+Introduction
+------------
+
+Doctrine Cache provides a very simple interface for which several out
+of the box implementations are provided:
+
+- ApcCache (requires ext/apc)
+- ArrayCache (in memory, lifetime of the request)
+- FilesystemCache (not optimal for high concurrency)
+- MemcacheCache (requires ext/memcache)
+- MemcachedCache (requires ext/memcached)
+- PhpFileCache (not optimal for high concurrency)
+- RedisCache.php (requires ext/phpredis)
+- WinCacheCache.php (requires ext/wincache)
+- XcacheCache.php (requires ext/xcache)
+- ZendDataCache.php (requires Zend Server Platform)
+
+A simple code example using ``ArrayCache`` to cache data in memory for the lifetime
+of the request can be found below.
+
+.. code-block :: php
+
+ <?php
+
+ $cache = new \Doctrine\Common\Cache\ArrayCache();
+ $id = $cache->fetch("some key");
+ if (!$id) {
+ $id = do_something();
+ $cache->save("some key", $id);
+ }
+
+ ..
+
+ $cache->contains("some key");
+ $cache->delete("some key");
+
+ // not all cache backends provide stats, f.e. ArrayCache does not
+ $stats = $cache->getStats();
+ if (!empty($stats)) {
+ foreach ($stats as $key => $value) {
+ echo "$key: $value";
+ }
+ }

0 comments on commit cab4440

Please sign in to comment.