twistor/lru-cache

LRU 缓存实现

v1.0.0 2019-11-18 19:57 UTC

This package is auto-updated.

Last update: 2024-09-19 08:09:05 UTC


README

Author Build Status Coverage Status Quality Score Software License Packagist Version Total Downloads

LRU(最近最少使用)缓存允许你保持内存中的对象缓存。一旦达到容量限制,最老的缓存项将被移除。

安装

composer require twistor/lru-cache

使用

use Twistor\LruCache;

$cache = new LruCache(100);

$cache->put('my_key', 1);

$cache->get('my_key');

$cache->getWith('new_key', function ($key) {
   return 2;
});