Released 7 years ago , Last update 7 years ago

uCache - Universal cache. Manages all your cache expiration times, race conditions, locks and does it gracefully!


  • Tired of manually handling cache expiration?
  • Hate query spikes when cache expires?
  • Server can't handle cold starts?
  • Data gets overwritten due to race conditions?
  • SQL servers pukes from insane queries and large datasets?

Well, no more! finally a cache that can be used without feeling a pain in the neck. Ucache - the perfect solution for developers seeking highly automated cache mechanism. Using uCache with memcached, apc and / or file based caching will help you forget about expired cache query spikes, race conditions, cronjobs or even the 1 MB limit of memcached. But it doesn't end here - if parsing dynamic PHP scripts is getting slow, you can cache data straight to any type of static file.

What? Don't want to use memcached, apc or file based caching? Don't like the current implemention? Make your own handler! Provided API documentation will let you find everything you need.

Last but not least, the Ucache is lightweight. No external libraries, no unneeded code, just the bare bones of a highly automated caching mechanism.


  • Race condition prevention.
  • Multiple cache reset request on same data prevention.
  • Server cold start freeze prevention.
  • 1MB limit removal for Memcached handler.
  • Quota limit for Files handler.
  • Multiple instances with same or different cache handlers.
  • Memcached, Apc or file based caching supported.
  • API documention for developing your own custom cache handler.


  • Very useful when there is a need for speed on high database load applications without major it's changes and query rewrites.
  • Useful if server can't handle dynamic content requests and there is a need for static one.
  • Most likely there will be a noticable performance gain on any application. Try IT!*


  • PHP 5
  • PHP Memcached (If Memcached handler is used)
  • PHP Apc (If Apc handler is used)


14 day 14-day money-back guarantee


Personal License

  • Perpetual license

  • 1 site, unlimited servers

  • No distribution (hosted use only)

  • Commercial use

Usage instructions

Inlcude the Ucache base file:

/* Include Ucache base file */
require_once dirname(__FILE__) . '/Ucache.php';

Prime Ucache to your target object and method

/* Initialize Ucache using your object and it's method. */
$ucache = Ucache::init($object, 'method');

Get data from the cache

/* Set and get cache for 60 seconds using $parameters array of callback parameters to your method. */ 
$data = $ucache->useCache(60, $parameters);

Note: Additional usage examples are provided in readme.txt 

Custom handler implemention

In order to create your own custom handler, first you need to create two files:

  1. Handler_Name.php - Where `Name` can be anything you want. This will be your main handler file.
  2. Handler_Name_Config.php - Where `Name` should match the name chosen for the first file. This is your handler's config file.

Example: Handler_MyHandler.php, Handler_MyHandler_Config.php

The first file must have a class of the same name as it's name and it must extend Ucache_Core class. The second file can be empty if no configuration is needed for your handler. But in order to keep everything consistent, it must exist.

When writing your custom handler, you must implement 9 methods for Ucache to properly function. These methods are:

  • protected function _init() - Handler initializer. Should include anything needed to start your handler.
  • protected function _setExpiration($expiration) - Method that should set cache item's expiration time. *Note: The purpose of this method is to set cache expiration (in seconds) independant from the data in order to still be able to access cached data during the period when it's expired, but the reset hasn't finished yet.*
  • protected function _setLock($expiration) - Method that should set a lock for item that is being updated and no other process would do the same. *Note: Used to prevent multiple resets when cache expires.*
  • protected function _destroyLock() - Method that should remove the lock after item has been updated.
  • protected function _getData() - Method that should return data from cache.
  • protected function _storeData($data) - Method that should store data to cache.
  • protected function _cleanupUnused() - Method that should clean junk cache data if there is any. *Note: Ucache separates data and it's expiration, so junk (not used anymore) data can accumulate. This is the place where it should be deleted.*
  • public function destroyCache($key) - Method that should destroy data in cache.
  • public function expireCache($key) - Method that should expire cached data.

The logic flow for these methods is as follows:

  1. If cache is not yet expired - tries to return cached data.
  2. If lock already exists, tries to return cached data.
  3. If cache is expired and lock doesn't exist, tries to set data to cache:
    1. Retrieves data to store via user callback.
    2. Stores the data to cache.
    3. Tries to cleanup junk cache.
    4. Destroys lock.
    5. Returns the newly cached data.

Note: Although you can write your own custom handler, you can't change underlying caching logic.

Additional reference is provided in PhpDoc documentation within the docs/ directory.

2 licenses, starting from From » FREE View Licenses

Get A Quote

What do you need?
  • Custom development
  • Integration
  • Customization / Reskinning
  • Consultation
When do you need it?
  • Soon
  • Next week
  • Next month
  • Anytime

Thanks for getting in touch!

Your quote details have been received and we'll get back to you soon.

Or enter your name and Email
No comments have been posted yet.