<?php
namespace Engine\Cache; class LocalMemoryLinear implements \Engine\Cache\BaseInterface { private $data = []; private $maxItems = 30; private $maxRemovedItems = 20; private $minIntervalChecks = 10; private $sessionOps = 0; public function setStorageLimits($maxItems, $maxRemovedItems, $minIntervalChecks) { $this->maxItems = $maxItems; $this->maxRemovedItems = $maxRemovedItems; $this->minIntervalChecks = $minIntervalChecks; } public function set($key, $value, $expireTime=0) :void { if (!$key) { return ; } if ($value===null) { return ; } $this->sessionOps++; if ($this->sessionOps > $this->minIntervalChecks){ if(count($this->data) > $this->maxItems){ $this->data = array_slice($this->data, -1*$this->maxRemovedItems); } $this->sessionOps = 0; } if (is_object($value)) { $this->data[$key] = [ 'data'=> &$value, ]; } else { $this->data[$key] = [ 'data'=> $value, ]; } } public function get($key) { if (isset($this->data[$key])) { return $this->data[$key]['data']; } return null; } public function delete($key) :void { unset($this->data[$key]); } public function flush() :bool { $this->data = []; return true; } public function getInfo($key) { $return = [ 'exists' => array_key_exists($key, $this->data), 'key' => $key, 'lastGet' => null, 'hits' => null, ]; return $return; } } 