api de gestion de ticket, basé sur php-crud-api. Le but est de décorrélé les outils de gestion des données, afin
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

MemcacheCache.php 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace Tqdev\PhpCrudApi\Cache;
  3. class MemcacheCache implements Cache
  4. {
  5. protected $prefix;
  6. protected $memcache;
  7. public function __construct(string $prefix, string $config)
  8. {
  9. $this->prefix = $prefix;
  10. if ($config == '') {
  11. $address = 'localhost';
  12. $port = 11211;
  13. } elseif (strpos($config, ':') === false) {
  14. $address = $config;
  15. $port = 11211;
  16. } else {
  17. list($address, $port) = explode(':', $config);
  18. }
  19. $this->memcache = $this->create();
  20. $this->memcache->addServer($address, $port);
  21. }
  22. protected function create() /*: \Memcache*/
  23. {
  24. return new \Memcache();
  25. }
  26. public function set(string $key, string $value, int $ttl = 0): bool
  27. {
  28. return $this->memcache->set($this->prefix . $key, $value, 0, $ttl);
  29. }
  30. public function get(string $key): string
  31. {
  32. return $this->memcache->get($this->prefix . $key) ?: '';
  33. }
  34. public function clear(): bool
  35. {
  36. return $this->memcache->flush();
  37. }
  38. }