Search code examples
phpcachingmemorycache

How to use Cache_Lite for memory Caching


How to use Cache_Lite for memory Caching? In the document of constructor Cache_Lite::Cache_Lite, there is an option "memoryCaching" : enable / disable "Memory Caching" (NB : there is no lifetime for memory caching, only the end of the script)

There is not example of how to use it. Do I need to set the cacheDir? How to use it?


Solution

  • I would not use this class anymore. If you look at the source code, it has plenty of bad stuff in it, most importantly it is written for PHP 4, just like many PEAR classes.

    Investigating the memory cache feature, I found that it is simply an array that stores any results previously fetched from the file cache within the current request. So you won't get persistent memory caching like from Memcached or APC. There is a comment in the code stating that the memory cache feature should be considered "beta" quality.

    The description of the code claims the cache to be fast, but I doubt it. There are multiple calls to clearstatcache() which are effectively destroying any filesystem performance, just because there is a need to fetch the most current filemtime() instead of writing this information into the cached data in the file.

    If you are looking for a more current solution for caching, have a look at APC (might be available as opcode cache on your hosting machine), or Memcached, with barely any more overhead of implementation. If you need a file based caching, find out whether any framework you might use offers you something. Or do a quick Google search, which might end up with results like this: https://github.com/cosenary/Simple-PHP-Cache (not that I'm recommending this class).