The web based syslog https://lggr.io
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.4KB

  1. <?php
  2. class LggrCacheFile extends AbstractLggrCache {
  3. const MAXAGE = 300;
  4. // 5 minutes
  5. private $cachepath = null;
  6. function __construct() {
  7. $this->cachepath = __DIR__ . '/../cache/';
  8. }
  9. // constructor
  10. public function store($key, $value) {
  11. $fname = $this->getFilename($key);
  12. $s = serialize($value);
  13. file_put_contents($fname, $s);
  14. }
  15. // function
  16. public function retrieve($key) {
  17. $fname = $this->getFilename($key);
  18. if (file_exists($fname) && is_readable($fname)) {
  19. $ts = filemtime($fname);
  20. if (time() - $ts > self::MAXAGE) {
  21. unlink($fname);
  22. return null;
  23. } else {
  24. $s = file_get_contents($fname);
  25. return unserialize($s);
  26. } // if
  27. } else {
  28. return null;
  29. } // if
  30. }
  31. // function
  32. public function purge($key) {
  33. $fname = $this->getFilename($key);
  34. unlink($fname);
  35. }
  36. // function
  37. private function filterKey($key) {
  38. $sTmp = str_replace(' ', '-', $key);
  39. return preg_replace('/[^A-Za-z0-9\-]/', '', $sTmp);
  40. }
  41. // function
  42. private function getFilename($key) {
  43. return $this->cachepath . 'key_' . $this->filterKey($key) . '.data';
  44. } // function
  45. }
Social stuff:
Mastodon