retesere20

apcu-examples

Jun 26th, 2021 (edited)
9
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static function apcu_check() { if (!self::apcu_enabled()) throw new Exception('APCU module not enabled'); }
  2. public static function apcu_enabled() { return function_exists('apcu_enabled') && apcu_enabled(); }
  3. public static function apcu_get($uniqueid) { return \apcu_fetch($uniqueid); }
  4. public static function apcu_set($uniqueid, $data) { return \apcu_store($uniqueid, $data); }
  5.  
  6. public static function apcu_cached_time($uniqueid) {
  7. $info = apcu_key_info($uniqueid);
  8. try{
  9. return $info['mtime']; //https://www.php.net/manual/en/function.apcu-key-info.php
  10. }
  11. catch(\Exception $ex){
  12.  
  13. }
  14. return 0;
  15. }
  16.  
  17. // apcu_clear_cache()
  18. // apcu_exists ($key)
  19. // apcu_delete ($key)
  20. /* apcu_cache_info()
  21. (
  22. [num_slots] => 4099
  23. [ttl] => 0
  24. [num_hits] => 3
  25. [num_misses] => 1
  26. [num_inserts] => 7
  27. [num_entries] => 7
  28. [expunges] => 16
  29. [start_time] => 1623695589
  30. [mem_size] => 20656376
  31. [memory_type] => mmap
  32. [cache_list] => array of members: https://www.php.net/manual/en/function.apcu-key-info.php
  33. [deleted_list] => []
  34. [slot_distribution] => [
  35. [176] => 1 [341] => 1 [940] => 1 ...
  36. ]
  37. )
  38. */
  39.  
  40. ==============
  41. $timestamp = $this->apcu_cached_time ($uniqFileName);
  42. if (is_null($timestamp) || $timestamp + $expire_seconds<time() )
  43. {
  44. return $default;
  45. }
  46. $res = $this->apcu_get($uniqFileName);
  47. return ( !is_null($res) ? $res : $default );
  48.  
RAW Paste Data