Skip to content
Browse files

Added php tags to code sampling to enable highlighting.

  • Loading branch information...
1 parent 9b7dc77 commit d47191ac80d4f855eecf925ea1ba77b5b22e0f6c @tedivm committed May 12, 2012
Showing with 30 additions and 2 deletions.
  1. +6 −0 Handlers.rst
  2. +5 −1 Home.rst
  3. +19 −1 Usage.rst
View
6 Handlers.rst
@@ -17,6 +17,8 @@ The StashFileSystem handler stores each item in a php script, as native php. Uns
The unix permission for new directories. Defaults to 0770.
.. code-block:: php
+
+ <?php
// Uses a install specific default path if none is passed.
$handler = new StashFileSystem();
@@ -45,6 +47,7 @@ An alternative file based caching backend is the StashSqlite handler. It can use
.. code-block:: php
+ <?php
// StashSqlite
// Uses a install specific default path if none is passed.
@@ -67,6 +70,7 @@ The APC extension is one of the most well known php caching extensions, allowing
.. code-block:: php
+ <?php
// Uses a install specific default path if none is passed.
$handler = new StashApc();
@@ -98,6 +102,7 @@ Memcached is a client/server application which allows machines to pool their mem
.. code-block:: php
+ <?php
// One Server
$handler = new Stash\Handler\Memcache(array('servers' => array('127.0.0.1', '11211')));
@@ -133,6 +138,7 @@ Upon creation the handler takes in an array of handlers as an option, with each
.. code-block:: php
+ <?php
$subHandlers = array();
$subHandlers[] = new Stash\Handler\Apc();
$subHandlers[] = new Stash\Handler\FileSystem();
View
6 Home.rst
@@ -52,6 +52,7 @@ Stash functions as a key-value store: you place things into the cache using a ke
.. code-block:: php
+ <?php
$stash = $pool->getCache('fruit');
$stash->store('apple');
@@ -61,6 +62,8 @@ Stash functions as a key-value store: you place things into the cache using a ke
This works between requests as well.
.. code-block:: php
+
+ <?php
// First Request
$stash = $pool->getCache('fruit');
$stash->store('apple');
@@ -74,6 +77,7 @@ Putting this together with the rest of Stash allows for a simple yet flexible wa
.. code-block:: php
+ <?php
function getUserInfo($userId)
{
$pool = $this->cachePool;
@@ -111,4 +115,4 @@ For an in-depth look at using Stash take a look at `Usage <Usage.rst>`_ and `Han
License
=======
-Stash is licensed under the New BSD License. This means you are free to use it in any of your projects, proprietary or open source. While you aren't obligated to contribute back, any bug fixes or enhancements are appreciated -- besides, getting your code into the main branch is so much easier than maintaining your own fork.
+Stash is licensed under the New BSD License. This means you are free to use it in any of your projects, proprietary or open source. While you aren't obligated to contribute back, any bug fixes or enhancements are appreciated -- besides, getting your code into the main branch is so much easier than maintaining your own fork.
View
20 Usage.rst
@@ -12,6 +12,7 @@ Creating a basic Stash object is simple:
.. code-block:: php
+ <?php
$stash = new Stash\Cache();
// Set the "key", which is the path the Stash object points to.
@@ -22,6 +23,7 @@ This will create a cache object with no cross request storage, meaning the data
.. code-block:: php
+ <?php
// Create Handler with default options
$stashFileSystem = new Stash\Handler\FileSystem();
@@ -33,8 +35,10 @@ This will create a cache object with no cross request storage, meaning the data
$stash->setupKey('path/to/data');
Each handler object can be used by many different cache objects, so that any initial setup and overhead (database connections, file handlers, etc.) can be done only once per request. In order to simplify this process, the Pool class automates the process of handler creation to ensure that all cache objects use the same handlers.
+
.. code-block:: php
+ <?php
// Create Handler with default options
$stashFileSystem = new Stash\Handler\FileSystem();
@@ -61,6 +65,7 @@ Stash methods that accept keys can accept them in two forms: as a slash-delimite
.. code-block:: php
+ <?php
// Pass the key as a string
$stash = $pool->getCache('models/users/32/info');
@@ -80,6 +85,7 @@ Using these three functions, you can create simple cache blocks -- pieces of cod
.. code-block:: php
+ <?php
// Attempt to "get"
$data = $stash->get();
@@ -100,6 +106,7 @@ The *store* function can take the expiration as an additional argument. This exp
.. code-block:: php
+ <?php
// Using an age.
$data = $stash->get();
if($stash->isMiss())
@@ -130,6 +137,7 @@ Sometimes, when a cache item expires, multiple requests might come in for that i
.. code-block:: php
+ <?php
// Get the data from the cache using the "STASH_SP_OLD" technique for dealing with stampedes
$userInfo = $stash->get(Stash\Cache::STASH_SP_OLD);
@@ -160,6 +168,7 @@ By default Stash simply returns true for the "isMiss" function whenever the cach
.. code-block:: php
+ <?php
// preserves backward compatibility.
$stash->get();
@@ -175,8 +184,10 @@ STASH_SP_PRECOMPUTE
The personal favorite method of the Stash developers, this method causes Stash to recalculate the cached item _before_ it misses.
When this method is used Stash->get takes one additional argument, the amount of time (in seconds) before the expiration when it should regenerate the cache.
+
.. code-block:: php
+ <?php
// five minutes before the cache expires one instance will return a miss, causing the cache to regenerate.
$stash->get(STASH_SP_PRECOMPUTE, 300);
@@ -187,6 +198,7 @@ When this method is enabled and a different instance has called the lock functio
.. code-block:: php
+ <?php
$stash->get(STASH_SP_OLD);
// return false if another Stash instance is rebuilding the cached item even though the returned item is stale
@@ -201,6 +213,7 @@ This method takes one additional argument, the value to be returned while stampe
.. code-block:: php
+ <?php
$stash->get(STASH_SP_VALUE, 'Return this if stampede protection stops a miss');
// returns true only if the value is stale and no other processes have stated rebuilding the value.
@@ -215,6 +228,7 @@ When this method is used Stash->get takes two additional arguments, the time (in
.. code-block:: php
+ <?php
// sleeps for .5 seconds, reattempts to load the cache,
// then sleeps again for another .5 seconds before making it's last attempt
$stash->get(STASH_SP_SLEEP, 500, 2);
@@ -226,6 +240,7 @@ Clearing data is just as simple as getting it. As with the *get* and *store* fun
.. code-block:: php
+ <?php
// Clearing a key.
$stash = new Stash\Cache($handler);
$stash->setupKey('path/to/data/specific/123')
@@ -244,6 +259,7 @@ The Pool class can also clear the entire cache:
.. code-block:: php
+ <?php
$pool->flush();
@@ -254,6 +270,7 @@ The *purge* function removes stale data from the cache backends while leaving cu
.. code-block:: php
+ <?php
$stashFileSystem = new Stash\Handler\FileSystem();
// Purge the FileSystem
@@ -264,4 +281,5 @@ The Pool class can also purge the cache:
.. code-block:: php
- $pool->purge();
+ <?php
+ $pool->purge();

0 comments on commit d47191a

Please sign in to comment.
Something went wrong with that request. Please try again.