/** * Executes a statement and caches the result. * * Of course returns the cached result if called again and cached result is still alive. * @param string $sql SQL statement * @param array $prms Arguments for the query * @param int $lifetime Lifetime in seconds * @return ResultSet The ResultSet */ function CacheExecuteSql($sql, $prms = array(), $lifetime = 300) { if (!system_is_module_loaded('globalcache')) { return $this->ExecuteSql($sql, $prms); } $key = 'DB_Cache_Sql_' . md5($sql . serialize($prms)); $null = null; if (is_null($res = cache_get($key, $null, true, false))) { $res = $this->ExecuteSql($sql, $prms); if ($res) { $res->fetchAll(); $data = $res->serialize(); cache_set($key, $data, $lifetime, true, false); } } else { $res = ResultSet::unserialize($res); } return $res; }