/** * Given the hash of a some data, check to see whether it exists in * `tbl_cache`. If no cached object is found, this function will return * false, otherwise the cached object will be returned as an array. * * @param string $hash * The hash of the Cached object, as defined by the user * @return array|boolean * An associative array of the cached object including the creation time, * expiry time, the hash and the data. If the object is not found, false will * be returned. */ public function read($hash) { if ($c = $this->Database->fetchRow(0, "SELECT SQL_NO_CACHE * FROM `tbl_cache` WHERE `hash` = '{$hash}' AND (`expiry` IS NULL OR UNIX_TIMESTAMP() <= `expiry`) LIMIT 1")) { if (!($c['data'] = Cacheable::decompressData($c['data']))) { $this->delete($hash); return false; } return $c; } $this->delete(); return false; }
/** * Given the hash of a some data, check to see whether it exists in * `tbl_cache`. If no cached object is found, this function will return * false, otherwise the cached object will be returned as an array. * * @param string $hash * The hash of the Cached object, as defined by the user * @param string $namespace * The namespace allows a group of data to be retrieved at once * @return array|boolean * An associative array of the cached object including the creation time, * expiry time, the hash and the data. If the object is not found, false will * be returned. */ public function read($hash, $namespace = null) { $data = false; // Check namespace first if (!is_null($namespace)) { $data = $this->Database->fetch("\n SELECT SQL_NO_CACHE *\n FROM `tbl_cache`\n WHERE `namespace` = '{$namepspace}'\n AND (`expiry` IS NULL OR UNIX_TIMESTAMP() <= `expiry`)\n "); } // Then check hash if (!is_null($hash)) { $data = $this->Database->fetchRow(0, "\n SELECT SQL_NO_CACHE *\n FROM `tbl_cache`\n WHERE `hash` = '{$hash}'\n AND (`expiry` IS NULL OR UNIX_TIMESTAMP() <= `expiry`)\n LIMIT 1\n "); } // If the data exists, see if it's still valid if ($data) { if (!($data['data'] = Cacheable::decompressData($data['data']))) { $this->delete($hash, $namespace); return false; } return $data; } $this->delete(null, $namespace); return false; }