dev-master
9999999-dev https://github.com/syntaqx/cachewSimply Powerful PHP Caching
The Requires
- php >=5.3.3
The Development Requires
cache caching
Simply Powerful PHP Caching
Cachew is an open source object-oriented library built in PHP 5.3. Using best practices and thoughtful design, Cachew provides you decoupled and unit-testable code., (*1)
The Cachew library has the following requirements:, (*2)
And, depending on which driver you plan to use, at least one of the following:, (*3)
Cachew implements multiple drivers, allowing you to either pick your favorite, or use which driver makes the most sense for the task at hand. Each driver has constructor-injection requirements to allow you to utilize it with the rest of your system. If the example below doesn't make sense, just check out their docblocks!, (*4)
$cache = new Cachew\Driver\APC('application-key'); $cache = new Cachew\Driver\File('application-key', $cacheDirectory); $cache = new Cachew\Driver\Memcache('application-key', $memcache); $cache = new Cachew\Driver\Memcached('application-key', $memcached);
Also, if you check out the code example we've provided (found at
/example/index.php
), you'll see that we're using the Cachew gateway class!
It both makes instancing a whole lot easier, and also makes sure you don't have
duplicate objects lying around by implementing the Singleton pattern., (*5)
$cache = Cachew\Cachew::instance('file');
The methods you need to consider while working with Cachew are as follows:
set
, get
, exists
, remember
, and forget
. Each of the methods do
something a a little bit different, and most of them are self explanatory, but
here are their definitions:, (*6)
key
, value
, minutes
= 60)Write an item to the cache for a given number of minutes, (*7)
key
, default
= null)Get an item from the cache. If the item doesn't exist in the cache, return a default value., (*8)
key
)Determine if an item exists in the cache, (*9)
key
, default
= null, minutes
= 60)Get an item from the cache. If the item doesn't exist in the cache, store the default value in the cache., (*10)
key
)Delete an item from the cache, (*11)
Everything implemented here is meant to provide you all the power you need from a cache, with as little headache as possible. Go ahead, try it out! Let us know what you think!, (*12)
Well, you have a couple of options on that., (*13)
They're pretty simple. All you need to do is pass your configurations to the object like so (feel free to exchange the word Memcached for Memcache, because they're exactly the same to use), (*14)
Cachew\Memcached::$configuration = array( array('host' => '127.0.0.1', 'port' => 11211, 'weight' => 50), array('host' => '192.168.2.10', 'port' => 11211, 'weight' => 50), );
After you've done that, just call the instancer method, and you'll have yourself a fully functional Memcached connection to do whatever you want with!, (*15)
Cachew\Memcached::instance();
You can, but there's two things that happen if you choose to:, (*16)
Cachew::instance('memcached');
without using our classes. Sorry!We've tried extremely hard to keep our library as simple to understand as possible. So, we've tried to do our absolute best to sum up the power of Cachew with just this one page documentation., (*17)
But, we've also done a lot of inline-documentation that can be viewed through our generated API docs allowing you to understand more of the technicalities involved to making everything so powerfully simple!, (*18)
So, if you have any questions, please feel free to ask. But we both know you'll pick it up in no time!, (*19)
Simply Powerful PHP Caching
cache caching