Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/location/lib/common/ |
Upload File : |
<?php namespace Bitrix\Location\Common; /** * Class CachePool * @package Bitrix\Location\Common */ class Pool { /** @var int */ protected $poolSize = 0; /** @var array */ protected $items = []; /** * CachePool constructor. * @param int $poolSize * @param array $items */ public function __construct(int $poolSize) { $this->poolSize = $poolSize; } /** * @return array */ public function getItems(): array { return $this->items; } public function cleanItems(): void { $this->items = []; } /** * @param array $items */ public function setItems(array $items): void { $this->items = $items; } /** * @param string $index * @return mixed */ public function getItem(string $index) { $result = null; if(isset($this->items[$index])) { $result = $this->items[$index]; //come up used items unset($this->items[$index]); $this->items[$index] = $result; } return $result; } /** * @param string $index * @param mixed $value */ public function addItem(string $index, $value): void { $this->items[$index] = $value; $delta = count($this->items) - $this->poolSize; if($delta > 0) { $this->items = $this->decreaseSize($delta, $this->items); } } /** * @return int */ public function getItemsCount(): int { return count($this->items); } /** * @param string $index */ public function deleteItem(string $index): void { if(isset($this->items[$index])) { unset($this->items[$index]); } } /** * @param int $delta * @param array $items * @return array */ protected function decreaseSize(int $delta, array $items): array { if($delta <= 0 || count($items) <= 0) { return $items; } do { reset($items); unset($items[key($items)]); $delta--; } while($delta > 0); return $items; } }