SugarCRM Developer Blog

New in Sugar 6.2: Enhanced SugarCache

31 Mar, 2011
Posted By: John Mertic

One area of the app that got a bit of focus during the Sugar 6.2 development cycle is the SugarCache layer. SugarCache is designed to provide a consistent API to the various third party caches available for use with PHP, such as APC, Memcache, Wincache, and Zend Cache. This allows us to easily ( and most often, transparently ) support any of those caches if they are available on your system with little to no configuration needed. We do this by having a factory interface which will detect what caching mechanism is available, and then call the correct backend to add, retrieve, or delete items from the cache.

In Sugar 6.2, we refactored this interface to provide some new abilities, namely

  • Added an Object-oriented API in addition to the existing procedural API. Here’s a quick mapping of what the existing procedural methods are and how to do the same with the OOP API.
Procedural API OOP API
sugar_cache_put($key, $value) SugarCache::instance()->$key = $value
sugar_cache_retrieve($key) SugarCache::instance()->$key
sugar_cache_clear($key) unset(SugarCache::instance()->$key)
sugar_cache_reset() SugarCache::instance()->reset()
  • Improved the existing backends for better detection of availability and more efficient use of the given backend APIs.
  • Added sugar config setting ‘external_cache_force_backend’ where you can skip the backend detection logic and instead always use the specified caching backend.
  • Added an API to Redis using the PHP Redis extension.
  • Enable developers to build their own caching backends to use with Sugar. To do this, you’ll need to implement the 4 methods that handle dealing with the external cache itself ( _setExternal(), _getExternal(), _clearExternal(), and _resetExternal() ) along with adding any needed rules for detecting your backend being available to Sugar in the useBackend() method and setting the priority for detection with the $_priority property. Below is the code used for the Redis backend which illustrates this.

These enhancements now provide a much more robust and cleaner way to integrate new and upcoming caching platforms into the product in the future.

Have feedback for us? Drop us a line.
Terms & Conditions | Privacy | Trademark Info | Contact Info | FAQs | SugarCRM Inc.© 2004 - 2009 All rights reserved.