Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marvin255/in-memory-cache
PSR-16 implementation for cache that is stored in array.
https://github.com/marvin255/in-memory-cache
cache php psr-16
Last synced: about 1 month ago
JSON representation
PSR-16 implementation for cache that is stored in array.
- Host: GitHub
- URL: https://github.com/marvin255/in-memory-cache
- Owner: marvin255
- License: mit
- Created: 2021-05-10T07:47:47.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-06-11T21:30:24.000Z (5 months ago)
- Last Synced: 2024-06-12T05:45:25.676Z (5 months ago)
- Topics: cache, php, psr-16
- Language: PHP
- Homepage:
- Size: 36.1 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# InMemoryCache
[![Build Status](https://github.com/marvin255/in-memory-cache/workflows/marvin255_in_memory_cache/badge.svg)](https://github.com/marvin255/in-memory-cache/actions?query=workflow%3A%22marvin255_in_memory_cache%22)
Simple [PSR-16](https://www.php-fig.org/psr/psr-16/) implementation which uses internal array to store data.
## Usage
```php
use Marvin255\InMemoryCache\InMemoryCache;$maxCacheSize = 10000; // only 10000 can be stored by this object
$defaultTTL = 60; // 60 seconds as default TTL$cache = new InMemoryCache($maxCacheSize, $defaultTTL);
```## Decorator
Decorator allows to use two caches in the same time. All data from basic cache (e.g. redis based cache) will be also stored in InMemoryCache. This decorator can reduce requests amount for long-living php processes.
```php
use Marvin255\InMemoryCache\InMemoryCache;
use Marvin255\InMemoryCache\CompositeCache;$maxCacheSize = 10000; // only 10000 can be stored by this object
$defaultTTL = 60; // 60 seconds as default TTL$inMemoryCache = new InMemoryCache($maxCacheSize, $defaultTTL);
$redisCache = new MyAwesomeRedisCache();
$decorator = new CompositeCache($inMemoryCache, $redisCache);$decorator->get('test'); // this get will trigger a request to redis and save data to memory
$decorator->get('test'); // this get won't trigger any requests and just return data from memory
```