cache-install.inc 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * @file
  4. * Provides a stub cache implementation to be used during installation.
  5. */
  6. /**
  7. * Defines a stub cache implementation to be used during installation.
  8. *
  9. * The stub implementation is needed when database access is not yet available.
  10. * Because Drupal's caching system never requires that cached data be present,
  11. * these stub functions can short-circuit the process and sidestep the need for
  12. * any persistent storage. Obviously, using this cache implementation during
  13. * normal operations would have a negative impact on performance.
  14. */
  15. class DrupalFakeCache extends DrupalDatabaseCache implements DrupalCacheInterface {
  16. /**
  17. * Overrides DrupalDatabaseCache::get().
  18. */
  19. function get($cid) {
  20. return FALSE;
  21. }
  22. /**
  23. * Overrides DrupalDatabaseCache::getMultiple().
  24. */
  25. function getMultiple(&$cids) {
  26. return array();
  27. }
  28. /**
  29. * Overrides DrupalDatabaseCache::set().
  30. */
  31. function set($cid, $data, $expire = CACHE_PERMANENT) {
  32. }
  33. /**
  34. * Overrides DrupalDatabaseCache::clear().
  35. */
  36. function clear($cid = NULL, $wildcard = FALSE) {
  37. // If there is a database cache, attempt to clear it whenever possible. The
  38. // reason for doing this is that the database cache can accumulate data
  39. // during installation due to any full bootstraps that may occur at the
  40. // same time (for example, Ajax requests triggered by the installer). If we
  41. // didn't try to clear it whenever this function is called, the data in the
  42. // cache would become stale; for example, the installer sometimes calls
  43. // variable_set(), which updates the {variable} table and then clears the
  44. // cache to make sure that the next page request picks up the new value.
  45. // Not actually clearing the cache here therefore leads old variables to be
  46. // loaded on the first page requests after installation, which can cause
  47. // subtle bugs, some of which would not be fixed unless the site
  48. // administrator cleared the cache manually.
  49. try {
  50. if (class_exists('Database')) {
  51. parent::clear($cid, $wildcard);
  52. }
  53. }
  54. // If the attempt at clearing the cache causes an error, that means that
  55. // either the database connection is not set up yet or the relevant cache
  56. // table in the database has not yet been created, so we can safely do
  57. // nothing here.
  58. catch (Exception $e) {
  59. }
  60. }
  61. /**
  62. * Overrides DrupalDatabaseCache::isEmpty().
  63. */
  64. function isEmpty() {
  65. return TRUE;
  66. }
  67. }