From e1ad90ba40b74ec103b9113e49b9792b2b422d22 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sun, 13 Sep 2009 17:49:51 +0000 Subject: - Patch #575360 by dropcube: added API function to check if a cache bin is empty. --- includes/cache-install.inc | 5 ++++- includes/cache.inc | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) (limited to 'includes') diff --git a/includes/cache-install.inc b/includes/cache-install.inc index 3ab41410d..3be7588eb 100644 --- a/includes/cache-install.inc +++ b/includes/cache-install.inc @@ -28,5 +28,8 @@ class DrupalFakeCache implements DrupalCacheInterface { function clear($cid = NULL, $wildcard = FALSE) { } - + + function isEmpty() { + return TRUE; + } } diff --git a/includes/cache.inc b/includes/cache.inc index e87e2f889..6069ce004 100644 --- a/includes/cache.inc +++ b/includes/cache.inc @@ -167,6 +167,21 @@ function cache_clear_all($cid = NULL, $bin = NULL, $wildcard = FALSE) { return _cache_get_object($bin)->clear($cid, $wildcard); } +/** + * Check if a cache bin is empty. + * + * A cache bin is considered empty if it does not contain any valid data for any + * cache ID. + * + * @param $bin + * The cache bin to check. + * @return + * TRUE if the cache bin specified is empty. + */ +function cache_is_empty($bin) { + return _cache_get_object($bin)->isEmpty(); +} + /** * Interface for cache implementations. * @@ -260,6 +275,17 @@ interface DrupalCacheInterface { * match. If '*' is given as $cid, the bin $bin will be emptied. */ function clear($cid = NULL, $wildcard = FALSE); + + /** + * Check if a cache bin is empty. + * + * A cache bin is considered empty if it does not contain any valid data for + * any cache ID. + * + * @return + * TRUE if the cache bin specified is empty. + */ + function isEmpty(); } /** @@ -449,4 +475,14 @@ class DrupalDatabaseCache implements DrupalCacheInterface { } } } + + function isEmpty() { + $this->garbageCollection(); + $query = db_select($this->bin); + $query->addExpression('1'); + $result = $query->range(0, 1) + ->execute() + ->fetchField(); + return empty($result); + } } -- cgit v1.2.3