diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2008-10-27 09:24:34 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2008-10-27 09:24:34 +0000 |
commit | f593f18131d6a0cbf30b558b208e86b9fc957f13 (patch) | |
tree | af665d7fb2f7ec17b1948c8d1146dd9a6deaba29 /lib/class/database_object.abstract.php | |
parent | 14019e88c5370df8251b8d9836ea5867b670af1c (diff) | |
download | ampache-f593f18131d6a0cbf30b558b208e86b9fc957f13.tar.gz ampache-f593f18131d6a0cbf30b558b208e86b9fc957f13.tar.bz2 ampache-f593f18131d6a0cbf30b558b208e86b9fc957f13.zip |
Commit, still no internet paying for it.. curse you free.fr
Diffstat (limited to 'lib/class/database_object.abstract.php')
-rw-r--r-- | lib/class/database_object.abstract.php | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/lib/class/database_object.abstract.php b/lib/class/database_object.abstract.php index 2005da55..5c6020c6 100644 --- a/lib/class/database_object.abstract.php +++ b/lib/class/database_object.abstract.php @@ -31,6 +31,14 @@ abstract class database_object { // Statistics for debugging public static $cache_hit = 0; + /** + * get_info + * retrieves the info from the database and puts it in the cache + * + * @param string $id + * @param string $table_name + * @return array + */ public function get_info($id,$table_name='') { $table_name = $table_name ? Dba::escape($table_name) : Dba::escape(strtolower(get_class($this))); @@ -58,19 +66,26 @@ abstract class database_object { */ public static function is_cached($index,$id) { - $is_cached = isset(self::$object_cache[$index][$id]); - - return $is_cached; + return isset(self::$object_cache[$index][$id]); } // is_cached /** - * get_from_cache + * get_from_cache * This attempts to retrive the specified object from the cache we've got here + * + * @param string $index + * @param string $id + * @return array */ public static function get_from_cache($index,$id) { - if (isset(self::$object_cache[$index][$id])) { + // Check if the object is set + if (isset(self::$object_cache) + && isset(self::$object_cache[$index]) + && isset(self::$object_cache[$index][$id]) + ) { + self::$cache_hit++; return self::$object_cache[$index][$id]; } @@ -82,12 +97,22 @@ abstract class database_object { /** * add_to_cache * This adds the specified object to the specified index in the cache + * + * @param string $index + * @param string $id + * @param array $data + * @return boolean */ public static function add_to_cache($index,$id,$data) { - - self::$object_cache[$index][$id] = $data; - - return true; + $hasbeenset = false; + + // Set the data if it is set + if (isset($data)) { + self::$object_cache[$index][$id] = $data; + $hasbeenset = true; + } + + return $hasbeenset; } // add_to_cache |