(this post is automatically translated from the original Italian version for your convenience. Sorry in advance for errors)

Cachet - php-based file system cache

Cachet is a php cache that uses the filesystem as storage or to store data.
This means that it can function without having a database.

Cachet is basically a "wrapper" function that we want (uhm.. You can say?) Cache the result.

Let's say we have a function a little bit slow, we just cache, such a function that makes a heavy query on a database.
We say that is acceptable to have a delay of 60 seconds, which is acceptable to have a cache time of 60 seconds

Before the cache ...

 $ Resultset = myfunction (parameter ");

With cachet.

 $ Cache = new cachet ();
 ...
 ...
 $ Resultset = $ cache-> get ('myfunction', Array ("parameter"), 60);
 ...

In practice, the class cachet has a method get, which goes by the name of the function call, parameters and time desired cache, example 60 seconds.

So it is quite simple plug into any php code.

Cachet is smart enough not to call the same function at the same time if it is already running.

Here is the example provided with the source:

 <? Php
   require_once ('cachet.php');
   function sum ($ a, $ b) (
     echo "Calling sum .. \ n";
     return $ a + $ b;
   )
   $ Cache = new cachet ();
   $ A = $ cache-> get ('sum', Array (4,2) 10);
   echo "[$ i] \ n";
   print_r ($ a);
 ?>

You can try it with PHP CLI (command line interpreter), or use it on a website.
The current version ever NOT remove the files (serialized objects and lock) in the temporary directory.
It 's convenient, if you use functions that always have different parameters, erase files older than a tot (maximum cache time) from the temporary directory with a script in crontab.

Es for 2 days

 find / tmp / cachet, ctime +2-exec rm-f '()' \;

Cachet is released under the Attribution-Share Alike 3.0

Similar Items