memcache.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * Elgg memcache support.
  4. *
  5. * Requires php5-memcache to work.
  6. *
  7. * @package Elgg.Core
  8. * @subpackage Cache.Memcache
  9. */
  10. /**
  11. * Return true if memcache is available and configured.
  12. *
  13. * @return bool
  14. */
  15. function is_memcache_available() {
  16. global $CONFIG;
  17. static $memcache_available;
  18. if ((!isset($CONFIG->memcache)) || (!$CONFIG->memcache)) {
  19. return false;
  20. }
  21. // If we haven't set variable to something
  22. if (($memcache_available !== true) && ($memcache_available !== false)) {
  23. try {
  24. $tmp = new \ElggMemcache();
  25. // No exception thrown so we have memcache available
  26. $memcache_available = true;
  27. } catch (Exception $e) {
  28. $memcache_available = false;
  29. }
  30. }
  31. return $memcache_available;
  32. }
  33. /**
  34. * Invalidate an entity in memcache
  35. *
  36. * @param int $entity_guid The GUID of the entity to invalidate
  37. *
  38. * @return void
  39. * @access private
  40. */
  41. function _elgg_invalidate_memcache_for_entity($entity_guid) {
  42. static $newentity_cache;
  43. if ((!$newentity_cache) && (is_memcache_available())) {
  44. $newentity_cache = new \ElggMemcache('new_entity_cache');
  45. }
  46. if ($newentity_cache) {
  47. $newentity_cache->delete($entity_guid);
  48. }
  49. }