<?php
 namespace App\ReportsData\EntityFields; class Cache { protected $values = []; static protected $instance; protected $maxCacheSizePerEntity = 2000; private function __construct() { } static public function getInstance() { if (!self::$instance) { self::$instance = new self(); } return self::$instance; } public function set($entity, $id, $value) { if ($value===null) { throw new \Exception("You cannot cache NULL for RD Entity fields classes."); } if ($this->maxCacheSizePerEntity<=0) { return ; } if ($this->values[$entity] and !$this->values[$entity][$id] and count($this->values[$entity])>=$this->maxCacheSizePerEntity) { $this->flushEntity($entity); } $this->values[$entity][$id] = $value; } public function get($entity, $id) { return $this->values[$entity][$id]; } public function flushAll() { $this->values = []; } public function flushEntity($entity) { unset($this->values[$entity]); } public function setMaxCacheSizePerEntity($maxCacheSizePerEntity) { $this->maxCacheSizePerEntity = $maxCacheSizePerEntity; } } 