HashLookupInterface.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * Very fast hash based lookup interface.
  4. *
  5. * This will work for any key-value store whether it's APC, Redis, memcache...
  6. * Rationale behind this is that Drupal calls hundreds of time per request the
  7. * drupal_lookup_path() function and we need it to be very fast. The key of
  8. * success to keep it stupid simple and coherent as the same time is that we
  9. * consider this backend as a cache (more or less permanent) that might be
  10. * cleared at any time, and synchronized as when necessary or incrementally.
  11. * This should be very fast.
  12. *
  13. * Redis implementation will be the following:
  14. *
  15. * Aliases are stored into a Redis HASH and are stored per language basis.
  16. * Key is:
  17. * [SITEPREFIX:]path:dst:LANGUAGE
  18. * Keys inside the hash are a MD5() of the source and values are the alias
  19. *
  20. * Sources are also stored the same way except the HASH key is the following:
  21. * [SITEPREFIX:]path:src:LANGUAGE
  22. * Keys inside the hash are a MD5() of the alias and values are the sources.
  23. *
  24. * In both case values are a comma separated list of string values.
  25. *
  26. * The MD5() should give us low collision algorithm and we'll keep it until
  27. * no one experiences any problem.
  28. *
  29. * Alias and sources are always looked up using the language, hence the
  30. * different keys for different languages.
  31. */
  32. interface Redis_Path_HashLookupInterface
  33. {
  34. /**
  35. * Alias HASH key prefix
  36. */
  37. const KEY_ALIAS = 'path:a';
  38. /**
  39. * Source HASH key prefix
  40. */
  41. const KEY_SOURCE = 'path:s';
  42. /**
  43. * Null value (not existing yet cached value)
  44. */
  45. const VALUE_NULL = '!';
  46. /**
  47. * Values separator for hash values
  48. */
  49. const VALUE_SEPARATOR = '#';
  50. /**
  51. * Alias is being inserted with the given source
  52. *
  53. * @param string $source
  54. * @param string $alias
  55. * @param string $language
  56. */
  57. public function saveAlias($source, $alias, $language = null);
  58. /**
  59. * Alias is being deleted for the given source
  60. *
  61. * @param string $source
  62. * @param string $alias
  63. * @param string $language
  64. */
  65. public function deleteAlias($source, $alias, $language = null);
  66. /**
  67. * A language is being deleted
  68. *
  69. * @param string $language
  70. */
  71. public function deleteLanguage($language);
  72. /**
  73. * Lookup any alias for the given source
  74. *
  75. * First that has been inserted wins over the others
  76. *
  77. * @param string $source
  78. * @param string $language
  79. *
  80. * @return string|null|false
  81. * - The string value if found
  82. * - null if not found
  83. * - false if set as non existing
  84. */
  85. public function lookupAlias($source, $language = null);
  86. /**
  87. * Lookup any source for the given alias
  88. *
  89. * First that has been inserted wins over the others
  90. *
  91. * @param string $alias
  92. * @param string $language
  93. *
  94. * @return string|null|false
  95. * - The string value if found
  96. * - null if not found
  97. * - false if set as non existing
  98. */
  99. public function lookupSource($alias, $language = null);
  100. }