Overview

Packages

  • ClipIt
    • clipit
      • api
    • urjc
      • backend
  • Elgg
    • Core
      • Access
      • Authentication
      • Cache
      • Caches
      • Core
      • DataMode
        • Site
      • DataModel
        • Annotations
        • Entities
        • Extender
        • File
        • Importable
        • Loggable
        • Notable
        • Object
        • User
      • DataStorage
      • Exception
      • Exceptions
        • Stub
      • FileStore
        • Disk
      • Groups
      • Helpers
      • HMAC
      • Memcache
      • Metadata
      • Navigation
      • ODD
      • Output
      • Plugins
        • Settings
      • Sessions
      • SocialModel
        • Friendable
        • Locatable
      • WebServicesAPI
      • Widgets
      • XML
      • XMLRPC
    • Exceptions
      • Stub
  • None
  • PHP

Classes

  • ElggHMACCache
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * ElggHMACCache
  4:  * Store cached data in a temporary database, only used by the HMAC stuff.
  5:  *
  6:  * @package    Elgg.Core
  7:  * @subpackage HMAC
  8:  */
  9: class ElggHMACCache extends ElggCache {
 10:     /**
 11:      * Set the Elgg cache.
 12:      *
 13:      * @param int $max_age Maximum age in seconds, 0 if no limit.
 14:      */
 15:     function __construct($max_age = 0) {
 16:         $this->setVariable("max_age", $max_age);
 17:     }
 18: 
 19:     /**
 20:      * Save a key
 21:      *
 22:      * @param string $key  Name
 23:      * @param string $data Value
 24:      *
 25:      * @return boolean
 26:      */
 27:     public function save($key, $data) {
 28:         global $CONFIG;
 29: 
 30:         $key = sanitise_string($key);
 31:         $time = time();
 32: 
 33:         $query = "INSERT into {$CONFIG->dbprefix}hmac_cache (hmac, ts) VALUES ('$key', '$time')";
 34:         return insert_data($query);
 35:     }
 36: 
 37:     /**
 38:      * Load a key
 39:      *
 40:      * @param string $key    Name
 41:      * @param int    $offset Offset
 42:      * @param int    $limit  Limit
 43:      *
 44:      * @return string
 45:      */
 46:     public function load($key, $offset = 0, $limit = null) {
 47:         global $CONFIG;
 48: 
 49:         $key = sanitise_string($key);
 50: 
 51:         $row = get_data_row("SELECT * from {$CONFIG->dbprefix}hmac_cache where hmac='$key'");
 52:         if ($row) {
 53:             return $row->hmac;
 54:         }
 55: 
 56:         return false;
 57:     }
 58: 
 59:     /**
 60:      * Invalidate a given key.
 61:      *
 62:      * @param string $key Name
 63:      *
 64:      * @return bool
 65:      */
 66:     public function delete($key) {
 67:         global $CONFIG;
 68: 
 69:         $key = sanitise_string($key);
 70: 
 71:         return delete_data("DELETE from {$CONFIG->dbprefix}hmac_cache where hmac='$key'");
 72:     }
 73: 
 74:     /**
 75:      * Clear out all the contents of the cache.
 76:      *
 77:      * Not currently implemented in this cache type.
 78:      *
 79:      * @return true
 80:      */
 81:     public function clear() {
 82:         return true;
 83:     }
 84: 
 85:     /**
 86:      * Clean out old stuff.
 87:      *
 88:      */
 89:     public function __destruct() {
 90:         global $CONFIG;
 91: 
 92:         $time = time();
 93:         $age = (int)$this->getVariable("max_age");
 94: 
 95:         $expires = $time - $age;
 96: 
 97:         delete_data("DELETE from {$CONFIG->dbprefix}hmac_cache where ts<$expires");
 98:     }
 99: }
100: 
API documentation generated by ApiGen 2.8.0