Results 1 to 3 of 3

Thread: New Cache API

  1. #1
    Jacob's Avatar
    Jacob is offline Senior Member
    Join Date
    Oct 2004
    Posts
    331

    Default New Cache API

    I have added a new cache mechanism in Sugar 4.5. It allows the caching and retrieval of arbitrary information within the same round trip, and if you have Zend Platform installed, it will share data with all requests on the server. This API will connect with more accelerators in the future. The user's of the API do not need to worry about whether or not an external cache is present. It is automatically detected and used. If necessary, the external cache can be disabled.

    I have used the API in several of the functions in include/utils.php. Many of them were being called multiple times with the same arguments.

    The implementation is located: include/utils/external_cache.php
    (all code subject to the SPL)

    PHP Code:
    /**
        * Retrieve a key from cache.  For the Zend Platform, a maximum age of 5 minutes is assumed.
        *
        * @param String $key -- The item to retrieve.
        * @return The item unserialized
        */
       
    function sugar_cache_retrieve($key)
       
       
    /**
        * Put a value in the cache under a key
        *
        * @param String $key -- Global namespace cache.  Key for the data.
        * @param Serializable $value -- The value to store in the cache.
        */
       
    function sugar_cache_put($key$value)
       
       
    /**
        * Clear a key from the cache.  This is used to invalidate a single key.
        *
        * @param String $key -- Key from global namespace
        */
       
    function sugar_cache_clear($key)
       
     
    /**
      * Turn off external caching for the rest of this round trip and for all round 
      * trips for the next cache timeout.  This function should be called when global arrays
      * are affected (studio, module loader, upgrade wizard, ... ) and it is not ok to 
      * wait for the cache to expire in order to see the change.
      */
     
    function sugar_cache_reset() 
    JSON is one of the modules that received the most benefit from the cache.

    at the top of the encode method, I added:
    PHP Code:
            $cache_key 'JSON_encode_'.$var;
               if(
    is_array($var) || is_object($var))
               {
                   
    $cache_key 'JSON_encode_'.md5(serialize($var));
               }
       
               
    // Use the global cache
               
    if($cache_value sugar_cache_retrieve($cache_key))
               {
                   return 
    $cache_value;
               } 
    When a value is about to be returned, I put the calculated value in the cache.
    PHP Code:
                   $value json_encode($var);
                   
    sugar_cache_put($cache_key$value);
                   return 
    $value
    Jacob
    Last edited by Jacob; 2006-08-25 at 10:52 PM. Reason: Updated with new API

  2. #2
    kbrill's Avatar
    kbrill is offline SugarCRM PS Engineer
    Join Date
    Jul 2004
    Location
    St Louis, MO
    Posts
    3,183

    Default Re: New Cache API

    You also need to add the following line in config.php to enable external cache.

    'external_cache_disabled' => false
    Kenneth Brill - Help Forum Moderator

    I do not respond to 'Private Messages'. Please email me directly instead

    When asking for help, PLEASE give us your Server Information and Version Numbers as asked for on the 'Post New Message' screen as well as any JavaScript errors shown at the bottom of the browser window.
    Help us Help You

  3. #3
    Jacob's Avatar
    Jacob is offline Senior Member
    Join Date
    Oct 2004
    Posts
    331

    Default Re: New Cache API

    The caching API determines which third party caching modules are available by looking for function declarations in PHP. If the function is available, it will enable that cache. You do not need to modify the config.php setting in order to get caching to work.

    Depending on the version of Sugar you are using, it will support different external caches and optionally validate the cache before use. In current releases, after it finds a cache is available, it will attempt to quickly validate that the cache is functional. It will then proceed to use it.

    External cache support Overview:
    http://www.sugarcrm.com/wiki/index.p...d_Accelerators

    Jacob

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •