Call for Beta Testers: Object Cache edition

I’m looking for a few brave and kind souls that would like to help beta test Object Caching in OpenVBX.

The current release of OpenVBX only supports APC and it only supports it for API query results. This new build supports local memory, database (MySQL), APC & Memcache. This new build shows great performance increases when either APC or Memcache is available.

Cache is implemented in two general areas:

General Object Cache

The first is a general object cache for OpenVBX. This layer is for objects used in OpenVBX like Flows, Users, Devices and Settings. Cache settings are manually configured using a cache config file in the OpenVBX config directory.

This layer has a 3 possible modes:

  • Local (single page load memory, default). This layer is used when either APC or Memcache is not available. It will simply create an cache for the current page load. While it doesn’t provide a drastic increase in performance, it does reduce a few database hits during a single page load.
  • APC. This layer uses the standard PHP APC library ( This build was developed and tested using APC installed via PECL.
  • Memcache. This layer uses the PECL Memcache library ( not the Memcached library though support for both would be easy to add if there’s actual demand). Multiple memcache server use is supported via the config file. This build was developed and tested using Memcache installed via PECL.

API Cache

The 2nd is an API cache. At this time the API cache uses only the database to cache the results of API requests. The API Cache adds a new table to the database. Despite being named API Cache, this cache layer can be used for just about any data that should be transient in nature.

Items to Test:

Everything – This change touches almost every corner of OpenVBX so testing will be comprehensive. Areas where weird behavior was observed or that required special attention while developing were: install/upgrade and login/logout. General operation was the easiest part of this integration.

Any Model that extends the custom MY_Model class will get object caching for free so long as objects are retrieved using the get() or search() methods. A good example of this is the VBX_User model in this build. Since most models in OpenVBX used inconsistent methods of querying for objects they’ve all been standardized as much as possible to take advantage of the new caches.


  • Regular cache can be turned on and off. The API cache is always on by default. This might change in the future if there’s demand for the ability to change the cache settings.
  • Each cache type implements the base OpenVBX_Cache_Abstract class to provide a consistent interface for all cache usage no matter what type of cache is used.
  • Each cache object is considered a group. Each group invalidates itself upon save, edit or delete, thus preserving the state of other cache objects whose states are unrelated and unaffected by modifications to other objects.
  • New cache types are easily added by extending the abstract cache class and performing cache specific operations using the private method interfaces.
  • The build identifies itself as OpenVBX 1.2b-object-cache r64 – it will update the database from the 1.1.2 release.
  • This version updates the database to add a table and to modify the users table by removing the online, last_seen and last_login fields. These fields have been moved to be user-settings to avoid having to modify the cache every time we modify the last_seen setting.


Cache is manually enabled and configured through a new file OpenVBX/config/cache.php. There are only a few options to configure:

  • cache_enabled, boolean, default: TRUE. Controls the activity of the object cache. This has no effect on the API cache.
  • cache_type, string, default: memory. Either memory, apc or memcache.
  • default_expires, int, default: 3600. Time in seconds that cache should be held on to for. This is the system default. Individual models can change the TTL for their objects. See the VBX_Call model for an example of setting a custom TTL.
  • memcache, Array. Example settings for using Memcache. Defaults to the host machine and standard Memcache port.

Object Cache Use

OpenVBX automatically starts the object caches wether they’re active or not. This allows code to set & check caches without having to worry about wether the cache is active or not. An inactive cache will act the same as an expired cache.

The two caches are registered with OpenVBX separetely but their use is the same.

$ci =& get_instance();
$ci->cache->... // Object cache
$ci->api_cache->... // API Cache

Both caches have the same interfaces and are generally interchangeable. The API cache uses the database for caching since we always want to cache these results while the object cache availability and mechanism may change based on server configuration.

Every cache object contains the same methods:

  • get($key, $group, $tenant_id) – retrieve a cached item. Returns a found object or FALSE if no cache object is found or if the TTL has expired.
  • set($key, $data, $group, $tenant_id, $expires) – set a cached item. Returns TRUE on success, FALSE on failure.
  • delete($key, $group, $tenant_id) – delete a cached item. Returns TRUE on success, FALSE on failure.
  • invalidate($group, $tenant_id) – invalidate the existing cached items in that group. Invalidation works differently depending upon the cache mechanism. For Memory and Database caches the groups items are deleted immediately. For APC & Memcache a generation key is incremented so that the next time an item is looked for the generation key will mismatch causing a failure to find the item.
  • flush() – flush the entire cache.


The new build can be found in GitHub in the branch labeled feature/object-cache ( It is recommended that you plan on working with the code or want to contribute back any fixes that you first fork the OpenVBX repository to your GitHub account. This way any bug fixes or modifications are just a pull request away.

If you don’t want to mess with all that, then grab a copy of the branch source and get to it.

This build is NOT READY for production. I’m looking for people to help put this through its paces in a dev environment.

The database configuration for this branch is not backwards-compatible with other versions of OpenVBX. If you chose to run this against your current data please run it against a copy of that data.

Thanks in advance!

Post a Comment

Your email is never shared. Required fields are marked *