Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
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.
 
 
 
 
 
 

72 lines
1.5 KiB

  1. <?php
  2. /**
  3. * cache api
  4. */
  5. class Cache {
  6. public static function get($key) {
  7. /*if (function_exists("apc_fetch") AND function_exists("apc_exists"))
  8. if (apc_exists($key))
  9. return(apc_fetch($key));*/
  10. $r = q("SELECT `v` FROM `cache` WHERE `k`='%s' limit 1",
  11. dbesc($key)
  12. );
  13. if (count($r)) {
  14. /*if (function_exists("apc_store"))
  15. apc_store($key, $r[0]['v'], 600);*/
  16. return $r[0]['v'];
  17. }
  18. return null;
  19. }
  20. public static function set($key,$value) {
  21. q("REPLACE INTO `cache` (`k`,`v`,`updated`) VALUES ('%s','%s','%s')",
  22. dbesc($key),
  23. dbesc($value),
  24. dbesc(datetime_convert()));
  25. /*if (function_exists("apc_store"))
  26. apc_store($key, $value, 600);*/
  27. }
  28. /*
  29. *
  30. * Leaving this legacy code temporaily to see how REPLACE fares
  31. * as opposed to non-atomic checks when faced with fast moving key duplication.
  32. * As a MySQL extension it isn't portable, but we're not yet very portable.
  33. */
  34. /*
  35. * $r = q("SELECT * FROM `cache` WHERE `k`='%s' limit 1",
  36. * dbesc($key)
  37. * );
  38. * if(count($r)) {
  39. * q("UPDATE `cache` SET `v` = '%s', `updated = '%s' WHERE `k` = '%s'",
  40. * dbesc($value),
  41. * dbesc(datetime_convert()),
  42. * dbesc($key));
  43. * }
  44. * else {
  45. * q("INSERT INTO `cache` (`k`,`v`,`updated`) VALUES ('%s','%s','%s')",
  46. * dbesc($key),
  47. * dbesc($value),
  48. * dbesc(datetime_convert()));
  49. * }
  50. * }
  51. */
  52. public static function clear(){
  53. q("DELETE FROM `cache` WHERE `updated` < '%s'",
  54. dbesc(datetime_convert('UTC','UTC',"now - 30 days")));
  55. }
  56. }