summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcatch2011-12-30 15:00:36 +0900
committercatch2011-12-30 15:00:36 +0900
commita8addadfad94db977547b3514d21aab867d5a5a4 (patch)
tree75af1bd586f75201af8fb8f1d10fc8a2085ca86e
parent7ecad2daeec201dc2e00ce668e4a812200c939bc (diff)
Issue #1272706 by catch, pillarsdotnet, Berdir, msonnabaum: Remove backwards compatibility layer for cache API.
-rw-r--r--core/includes/cache.inc235
-rw-r--r--core/includes/common.inc2
-rw-r--r--core/includes/menu.inc12
-rw-r--r--core/includes/module.inc8
-rw-r--r--core/includes/theme.inc4
-rw-r--r--core/modules/field/field.attach.inc2
-rw-r--r--core/modules/simpletest/tests/cache.test4
-rw-r--r--core/modules/system/system.install2
-rw-r--r--core/modules/update/update.module8
9 files changed, 39 insertions, 238 deletions
diff --git a/core/includes/cache.inc b/core/includes/cache.inc
index 5d82fa0..e8c7477 100644
--- a/core/includes/cache.inc
+++ b/core/includes/cache.inc
@@ -40,158 +40,19 @@ function cache($bin = 'cache') {
}
/**
- * Returns data from the persistent cache.
- *
- * Data may be stored as either plain text or as serialized data. cache_get
- * will automatically return unserialized objects and arrays.
- *
- * @param $cid
- * The cache ID of the data to retrieve.
- * @param $bin
- * The cache bin to store the data in. Valid core values are 'cache_block',
- * 'cache_bootstrap', 'cache_field', 'cache_filter', 'cache_form',
- * 'cache_menu', 'cache_page', 'cache_path', 'cache_update' or 'cache' for
- * the default cache.
- *
- * @return
- * The cache or FALSE on failure.
- */
-function cache_get($cid, $bin = 'cache') {
- return cache($bin)->get($cid);
-}
-
-/**
- * Returns data from the persistent cache when given an array of cache IDs.
- *
- * @param $cids
- * An array of cache IDs for the data to retrieve. This is passed by
- * reference, and will have the IDs successfully returned from cache removed.
- * @param $bin
- * The cache bin where the data is stored.
- *
- * @return
- * An array of the items successfully returned from cache indexed by cid.
- */
-function cache_get_multiple(array &$cids, $bin = 'cache') {
- return cache($bin)->getMultiple($cids);
-}
-
-/**
- * Stores data in the persistent cache.
- *
- * The persistent cache is split up into several cache bins. In the default
- * cache implementation, each cache bin corresponds to a database table by the
- * same name. Other implementations might want to store several bins in data
- * structures that get flushed together. While it is not a problem for most
- * cache bins if the entries in them are flushed before their expire time, some
- * might break functionality or are extremely expensive to recalculate. These
- * will be marked with a (*). The other bins expired automatically by core.
- * Contributed modules can add additional bins and get them expired
- * automatically by implementing hook_flush_caches().
- *
- * - cache: Generic cache storage bin (used for variables, theme registry,
- * locale date, list of simpletest tests etc).
- *
- * - cache_block: Stores the content of various blocks.
- *
- * - cache field: Stores the field data belonging to a given object.
- *
- * - cache_filter: Stores filtered pieces of content.
- *
- * - cache_form(*): Stores multistep forms. Flushing this bin means that some
- * forms displayed to users lose their state and the data already submitted
- * to them.
- *
- * - cache_menu: Stores the structure of visible navigation menus per page.
- *
- * - cache_page: Stores generated pages for anonymous users. It is flushed
- * very often, whenever a page changes, at least for every ode and comment
- * submission. This is the only bin affected by the page cache setting on
- * the administrator panel.
- *
- * - cache path: Stores the system paths that have an alias.
- *
- * - cache update(*): Stores available releases. The update server (for
- * example, drupal.org) needs to produce the relevant XML for every project
- * installed on the current site. As this is different for (almost) every
- * site, it's very expensive to recalculate for the update server.
- *
- * The reasons for having several bins are as follows:
- *
- * - smaller bins mean smaller database tables and allow for faster selects and
- * inserts
- * - we try to put fast changing cache items and rather static ones into
- * different bins. The effect is that only the fast changing bins will need a
- * lot of writes to disk. The more static bins will also be better cacheable
- * with MySQL's query cache.
- *
- * @param $cid
- * The cache ID of the data to store.
- * @param $data
- * The data to store in the cache. Complex data types will be automatically
- * serialized before insertion.
- * Strings will be stored as plain text and not serialized.
- * @param $bin
- * The cache bin to store the data in. Valid core values are 'cache_block',
- * 'cache_bootstrap', 'cache_field', 'cache_filter', 'cache_form',
- * 'cache_menu', 'cache_page', 'cache_update' or 'cache' for the default
- * cache.
- * @param $expire
- * One of the following values:
- * - CACHE_PERMANENT: Indicates that the item should never be removed unless
- * explicitly told to using cache_clear_all() with a cache ID.
- * - CACHE_TEMPORARY: Indicates that the item should be removed at the next
- * general cache wipe.
- * - A Unix timestamp: Indicates that the item should be kept at least until
- * the given time, after which it behaves like CACHE_TEMPORARY.
- */
-function cache_set($cid, $data, $bin = 'cache', $expire = CACHE_PERMANENT) {
- return cache($bin)->set($cid, $data, $expire);
-}
-
-/**
- * Expires data from the cache.
- *
- * If called without arguments, expirable entries will be cleared from the
- * cache_page and cache_block bins.
- *
- * @param $cid
- * If set, the cache ID to delete. Otherwise, all cache entries that can
- * expire are deleted.
- * @param $bin
- * If set, the cache bin to delete from. Mandatory argument if $cid is set.
- * @param $wildcard
- * If TRUE, cache IDs starting with $cid are deleted in addition to the
- * exact cache ID specified by $cid. If $wildcard is TRUE and $cid is '*',
- * the entire cache bin is emptied.
+ * Expires data from the block and page caches.
*/
-function cache_clear_all($cid = NULL, $bin = NULL, $wildcard = FALSE) {
- if (!isset($cid) && !isset($bin)) {
- // Clear the block cache first, so stale data will
- // not end up in the page cache.
- if (module_exists('block')) {
- cache('block')->expire();
- }
- cache('page')->expire();
- return;
+function cache_clear_all() {
+ // @todo: remove before release.
+ if (func_get_args()) {
+ throw new Exception(t('cache_clear_all() no longer takes arguments, use cache() instead.'));
}
- return cache($bin)->clear($cid, $wildcard);
-}
-
-/**
- * Checks 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($bin)->isEmpty();
+ // Clear the block cache first, so stale data will
+ // not end up in the page cache.
+ if (module_exists('block')) {
+ cache('block')->expire();
+ }
+ cache('page')->expire();
}
/**
@@ -327,25 +188,6 @@ interface DrupalCacheInterface {
function garbageCollection();
/**
- * Expires data from the cache.
- *
- * If called without arguments, expirable entries will be cleared from the
- * cache_page and cache_block bins.
- *
- * @param $cid
- * If set, the cache ID to delete. Otherwise, all cache entries that can
- * expire are deleted.
- * @param $wildcard
- * If set to TRUE, the $cid is treated as a substring
- * to match rather than a complete ID. The match is a right hand
- * match. If '*' is given as $cid, the bin $bin will be emptied.
- *
- * @todo: This method is deprecated, as its functionality is covered by more
- * targeted methods in the interface.
- */
- function clear($cid = NULL, $wildcard = FALSE);
-
- /**
* Checks if a cache bin is empty.
*
* A cache bin is considered empty if it does not contain any valid data for
@@ -425,11 +267,6 @@ class DrupalNullCache implements DrupalCacheInterface {
function garbageCollection() {}
/**
- * Implements DrupalCacheInterface::clear().
- */
- function clear($cid = NULL, $wildcard = FALSE) {}
-
- /**
* Implements DrupalCacheInterface::isEmpty().
*/
function isEmpty() {
@@ -450,8 +287,8 @@ class DrupalDatabaseCache implements DrupalCacheInterface {
* Constructs a new DrupalDatabaseCache object.
*/
function __construct($bin) {
- // All cache tables should be prefixed with 'cache_', apart from the
- // default 'cache' bin, which would look silly.
+ // All cache tables should be prefixed with 'cache_', except for the
+ // default 'cache' bin.
if ($bin != 'cache') {
$bin = 'cache_' . $bin;
}
@@ -522,9 +359,9 @@ class DrupalDatabaseCache implements DrupalCacheInterface {
// If enforcing a minimum cache lifetime, validate that the data is
// currently valid for this user before we return it by making sure the cache
// entry was created before the timestamp in the current session's cache
- // timer. The cache variable is loaded into the $user object by _drupal_session_read()
- // in session.inc. If the data is permanent or we're not enforcing a minimum
- // cache lifetime always return the cached data.
+ // timer. The cache variable is loaded into the $user object by
+ // _drupal_session_read() in session.inc. If the data is permanent or we're
+ // not enforcing a minimum cache lifetime always return the cached data.
if ($cache->expire != CACHE_PERMANENT && variable_get('cache_lifetime', 0) && $user->cache > $cache->created) {
// This cache data is too old and thus not valid for us, ignore it.
return FALSE;
@@ -562,7 +399,7 @@ class DrupalDatabaseCache implements DrupalCacheInterface {
->execute();
}
catch (Exception $e) {
- // The database may not be available, so we'll ignore cache_set requests.
+ // The database may not be available, so we'll ignore these calls.
}
}
@@ -617,12 +454,12 @@ class DrupalDatabaseCache implements DrupalCacheInterface {
$cache_flush = variable_get('cache_flush_' . $this->bin, 0);
if ($cache_flush == 0) {
- // This is the first request to clear the cache, start a timer.
+ // This is the first request to clear the cache; start a timer.
variable_set('cache_flush_' . $this->bin, REQUEST_TIME);
}
elseif (REQUEST_TIME > ($cache_flush + variable_get('cache_lifetime', 0))) {
- // Clear the cache for everyone, cache_lifetime seconds have
- // passed since the first request to clear the cache.
+ // Clear the cache for everyone; cache_lifetime seconds have passed
+ // since the first request to clear the cache.
db_delete($this->bin)
->condition('expire', CACHE_PERMANENT, '<>')
->condition('expire', REQUEST_TIME, '<')
@@ -631,7 +468,7 @@ class DrupalDatabaseCache implements DrupalCacheInterface {
}
}
else {
- // No minimum cache lifetime, flush all temporary cache entries now.
+ // No minimum cache lifetime; flush all temporary cache entries now.
db_delete($this->bin)
->condition('expire', CACHE_PERMANENT, '<>')
->condition('expire', REQUEST_TIME, '<')
@@ -649,7 +486,8 @@ class DrupalDatabaseCache implements DrupalCacheInterface {
// often since this will remove temporary cache items indiscriminately.
$cache_flush = variable_get('cache_flush_' . $this->bin, 0);
if ($cache_flush && ($cache_flush + variable_get('cache_lifetime', 0) <= REQUEST_TIME)) {
- // Reset the variable immediately to prevent a meltdown in heavy load situations.
+ // Reset the variable immediately to prevent a meltdown in heavy load
+ // situations.
variable_set('cache_flush_' . $this->bin, 0);
// Time to flush old cache data
db_delete($this->bin)
@@ -660,33 +498,6 @@ class DrupalDatabaseCache implements DrupalCacheInterface {
}
/**
- * Implements DrupalCacheInterface::clear().
- */
- function clear($cid = NULL, $wildcard = FALSE) {
- global $user;
-
- if (empty($cid)) {
- $this->expire();
- }
- else {
- if ($wildcard) {
- if ($cid == '*') {
- $this->flush();
- }
- else {
- $this->deletePrefix($cid);
- }
- }
- elseif (is_array($cid)) {
- $this->deleteMultiple($cid);
- }
- else {
- $this->delete($cid);
- }
- }
- }
-
- /**
* Implements DrupalCacheInterface::isEmpty().
*/
function isEmpty() {
diff --git a/core/includes/common.inc b/core/includes/common.inc
index 9da67ac..3d19d3e 100644
--- a/core/includes/common.inc
+++ b/core/includes/common.inc
@@ -6090,7 +6090,7 @@ function drupal_render_collect_attached($elements, $return = FALSE) {
* added to this string and is also part of the cache key in
* drupal_render_cache_set() and drupal_render_cache_get().
* @param $expire
- * The cache expire time, passed eventually to cache_set().
+ * The cache expire time, passed eventually to cache()->set().
* @param $granularity
* One or more granularity constants passed to drupal_render_cid_parts().
*
diff --git a/core/includes/menu.inc b/core/includes/menu.inc
index b687d3d..9412310 100644
--- a/core/includes/menu.inc
+++ b/core/includes/menu.inc
@@ -2612,17 +2612,7 @@ function menu_link_load($mlid) {
* Clears the cached cached data for a single named menu.
*/
function menu_cache_clear($menu_name = 'navigation') {
- $cache_cleared = &drupal_static(__FUNCTION__, array());
-
- if (empty($cache_cleared[$menu_name])) {
- cache('menu')->deletePrefix('links:' . $menu_name . ':');
- $cache_cleared[$menu_name] = 1;
- }
- elseif ($cache_cleared[$menu_name] == 1) {
- drupal_register_shutdown_function('cache_clear_all', 'links:' . $menu_name . ':', 'cache_menu', TRUE);
- $cache_cleared[$menu_name] = 2;
- }
-
+ cache('menu')->deletePrefix('links:' . $menu_name . ':');
// Also clear the menu system static caches.
menu_reset_static_cache();
}
diff --git a/core/includes/module.inc b/core/includes/module.inc
index 221ad60..63d18ce 100644
--- a/core/includes/module.inc
+++ b/core/includes/module.inc
@@ -700,10 +700,10 @@ function module_implements_reset() {
// request. Benchmarks show that the benefit of this caching outweighs the
// additional database hit even when using the default database caching
// backend and only a small number of modules are enabled. The cost of the
- // cache_get() is more or less constant and reduced further when non-database
- // caching backends are used, so there will be more significant gains when a
- // large number of modules are installed or hooks invoked, since this can
- // quickly lead to module_hook() being called several thousand times
+ // cache('bootstrap')->get() is more or less constant and reduced further when
+ // non-database caching backends are used, so there will be more significant
+ // gains when a large number of modules are installed or hooks invoked, since
+ // this can quickly lead to module_hook() being called several thousand times
// per request.
drupal_static_reset('module_implements');
cache('bootstrap')->set('module_implements', array());
diff --git a/core/includes/theme.inc b/core/includes/theme.inc
index 5304d25..94d69d2 100644
--- a/core/includes/theme.inc
+++ b/core/includes/theme.inc
@@ -652,7 +652,7 @@ function _theme_build_registry($theme, $base_theme, $theme_engine) {
// serve as the basic registry. Since the list of enabled modules is the same
// regardless of the theme used, this is cached in its own entry to save
// building it for every theme.
- if ($cached = cache_get('theme_registry:build:modules')) {
+ if ($cached = cache()->get('theme_registry:build:modules')) {
$cache = $cached->data;
}
else {
@@ -661,7 +661,7 @@ function _theme_build_registry($theme, $base_theme, $theme_engine) {
}
// Only cache this registry if all modules are loaded.
if (module_load_all(NULL)) {
- cache_set('theme_registry:build:modules', $cache);
+ cache()->set('theme_registry:build:modules', $cache);
}
}
diff --git a/core/modules/field/field.attach.inc b/core/modules/field/field.attach.inc
index aa91402..9291725 100644
--- a/core/modules/field/field.attach.inc
+++ b/core/modules/field/field.attach.inc
@@ -643,7 +643,7 @@ function field_attach_load($entity_type, $entities, $age = FIELD_LOAD_CURRENT, $
foreach ($entities as $id => $entity) {
$cids[] = "field:$entity_type:$id";
}
- $cache = cache_get_multiple($cids, 'cache_field');
+ $cache = cache('field')->getMultiple($cids);
// Put the cached field values back into the entities and remove them from
// the list of entities to query.
foreach ($entities as $id => $entity) {
diff --git a/core/modules/simpletest/tests/cache.test b/core/modules/simpletest/tests/cache.test
index 664247b..bca4e25 100644
--- a/core/modules/simpletest/tests/cache.test
+++ b/core/modules/simpletest/tests/cache.test
@@ -1,7 +1,7 @@
<?php
class CacheTestCase extends DrupalWebTestCase {
- protected $default_bin = 'cache_page';
+ protected $default_bin = 'page';
protected $default_cid = 'test_temporary';
protected $default_value = 'CacheTest';
@@ -166,7 +166,7 @@ class CacheSavingCase extends CacheTestCase {
*/
function testNoEmptyCids() {
$this->drupalGet('user/register');
- $this->assertFalse(cache_get(''), t('No cache entry is written with an empty cid.'));
+ $this->assertFalse(cache()->get(''), t('No cache entry is written with an empty cid.'));
}
}
diff --git a/core/modules/system/system.install b/core/modules/system/system.install
index 0157964..20e1dc1 100644
--- a/core/modules/system/system.install
+++ b/core/modules/system/system.install
@@ -1471,7 +1471,7 @@ function system_schema() {
'default' => 0,
),
'cache' => array(
- 'description' => "The time of this user's last post. This is used when the site has specified a minimum_cache_lifetime. See cache_get().",
+ 'description' => "The time of this user's last post. This is used when the site has specified a minimum_cache_lifetime. See DrupalCacheInterface::get().",
'type' => 'int',
'not null' => TRUE,
'default' => 0,
diff --git a/core/modules/update/update.module b/core/modules/update/update.module
index 5612b07..57a2854 100644
--- a/core/modules/update/update.module
+++ b/core/modules/update/update.module
@@ -724,10 +724,10 @@ function update_verify_update_archive($project, $archive_file, $directory) {
* plug-able cache system that assumes volatile caches.
*
* Update module still uses the {cache_update} table, but instead of using
- * cache_set(), cache_get(), and cache_clear_all(), there are private helper
- * functions that implement these same basic tasks but ensure that the cache
- * is not prematurely cleared, and that the data is always stored in the
- * database, even if memcache or another cache backend is in use.
+ * the cache API, there are private helper functions that implement these same
+ * basic tasks but ensure that the cache is not prematurely cleared, and that
+ * the data is always stored in the database, even if memcache or another cache
+ * backend is in use.
*/
/**