├── Changelog.md ├── LICENSE ├── README.md ├── composer.json └── IlluminateCachePool.php /Changelog.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. 4 | 5 | ## 0.4.0 6 | 7 | * Support for PHP 8.1 8 | * Drop support for PHP < 7.4 9 | * Allow psr/cache: ^1.0 || ^2.0 10 | 11 | ## 0.3.0 12 | 13 | ### Added 14 | 15 | * Hierarchical implementation 16 | * Support for PHP 8 17 | 18 | ## 0.2.0 19 | 20 | ### Fixed 21 | 22 | * Let composer install laravel 5.4, 5.5 and 5.6 23 | 24 | ## 0.1.0 25 | 26 | * First version 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Aaron Scherer, Tobias Nyholm 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Illuminate PSR-6 Cache pool 2 | [![Gitter](https://badges.gitter.im/php-cache/cache.svg)](https://gitter.im/php-cache/cache?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) 3 | [![Latest Stable Version](https://poser.pugx.org/cache/illuminate-adapter/v/stable)](https://packagist.org/packages/cache/illuminate-adapter) 4 | [![codecov.io](https://codecov.io/github/php-cache/illuminate-adapter/coverage.svg?branch=master)](https://codecov.io/github/php-cache/illuminate-adapter?branch=master) 5 | [![Total Downloads](https://poser.pugx.org/cache/illuminate-adapter/downloads)](https://packagist.org/packages/cache/illuminate-adapter) 6 | [![Monthly Downloads](https://poser.pugx.org/cache/illuminate-adapter/d/monthly.png)](https://packagist.org/packages/cache/illuminate-adapter) 7 | [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE) 8 | 9 | This is a PSR-6 cache implementation using Illuminate cache. It is a part of the PHP Cache organisation. To read about 10 | features like tagging and hierarchy support please read the shared documentation at [www.php-cache.com](http://www.php-cache.com). 11 | 12 | This is a PSR-6 to Illuminate bridge. 13 | 14 | ### Install 15 | 16 | ```bash 17 | composer require cache/illuminate-adapter 18 | ``` 19 | 20 | ## Use 21 | 22 | ```php 23 | use Illuminate\Cache\ArrayStore; 24 | use Cache\Adapter\Illuminate\IlluminateCachePool; 25 | 26 | // Create an instance of an Illuminate's Store 27 | $store = new ArrayStore(); 28 | 29 | // Wrap the Illuminate's store with the PSR-6 adapter 30 | $pool = new IlluminateCachePool($store); 31 | ``` 32 | 33 | 34 | ### Contribute 35 | 36 | Contributions are very welcome! Send a pull request to the [main repository](https://github.com/php-cache/cache) or 37 | report any issues you find on the [issue tracker](http://issues.php-cache.com). 38 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cache/illuminate-adapter", 3 | "description": "A PSR-6 cache implementation using Illuminate. This implementation supports tags", 4 | "license": "MIT", 5 | "type": "library", 6 | "keywords": [ 7 | "cache", 8 | "psr-6", 9 | "illuminate", 10 | "laravel", 11 | "tag" 12 | ], 13 | "authors": [ 14 | { 15 | "name": "Florian Voutzinos", 16 | "email": "florian@voutzinos.com", 17 | "homepage": "https://github.com/florianv" 18 | }, 19 | { 20 | "name": "Aaron Scherer", 21 | "email": "aequasi@gmail.com", 22 | "homepage": "https://github.com/aequasi" 23 | }, 24 | { 25 | "name": "Tobias Nyholm", 26 | "email": "tobias.nyholm@gmail.com", 27 | "homepage": "https://github.com/nyholm" 28 | } 29 | ], 30 | "homepage": "http://www.php-cache.com/en/latest/", 31 | "require": { 32 | "php": ">=7.4", 33 | "cache/adapter-common": "^1.0", 34 | "cache/hierarchical-cache": "^1.0", 35 | "illuminate/cache": "^5.4 || ^5.5 || ^5.6", 36 | "psr/cache": "^1.0 || ^2.0", 37 | "psr/simple-cache": "^1.0" 38 | }, 39 | "require-dev": { 40 | "cache/integration-tests": "^0.17", 41 | "mockery/mockery": "^1.0", 42 | "phpunit/phpunit": "^7.5.20 || ^9.5.10" 43 | }, 44 | "provide": { 45 | "psr/cache-implementation": "^1.0", 46 | "psr/simple-cache-implementation": "^1.0" 47 | }, 48 | "minimum-stability": "dev", 49 | "prefer-stable": true, 50 | "autoload": { 51 | "psr-4": { 52 | "Cache\\Adapter\\Illuminate\\": "" 53 | }, 54 | "exclude-from-classmap": [ 55 | "/Tests/" 56 | ] 57 | }, 58 | "extra": { 59 | "branch-alias": { 60 | "dev-master": "1.1-dev" 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /IlluminateCachePool.php: -------------------------------------------------------------------------------- 1 | , Tobias Nyholm 7 | * 8 | * This source file is subject to the MIT license that is bundled 9 | * with this source code in the file LICENSE. 10 | */ 11 | 12 | namespace Cache\Adapter\Illuminate; 13 | 14 | use Cache\Adapter\Common\AbstractCachePool; 15 | use Cache\Adapter\Common\PhpCacheItem; 16 | use Cache\Hierarchy\HierarchicalCachePoolTrait; 17 | use Cache\Hierarchy\HierarchicalPoolInterface; 18 | use Illuminate\Contracts\Cache\Store; 19 | 20 | /** 21 | * This is a bridge between PSR-6 and an Illuminate cache store. 22 | * 23 | * @author Florian Voutzinos 24 | */ 25 | class IlluminateCachePool extends AbstractCachePool implements HierarchicalPoolInterface 26 | { 27 | use HierarchicalCachePoolTrait; 28 | 29 | /** 30 | * @type Store 31 | */ 32 | protected $store; 33 | 34 | /** 35 | * @param Store $store 36 | */ 37 | public function __construct(Store $store) 38 | { 39 | $this->store = $store; 40 | } 41 | 42 | /** 43 | * {@inheritdoc} 44 | */ 45 | protected function storeItemInCache(PhpCacheItem $item, $ttl) 46 | { 47 | $ttl = null === $ttl ? 0 : $ttl / 60; 48 | 49 | $data = serialize([true, $item->get(), $item->getTags(), $item->getExpirationTimestamp()]); 50 | 51 | $this->store->put($this->getHierarchyKey($item->getKey()), $data, $ttl); 52 | 53 | return true; 54 | } 55 | 56 | /** 57 | * {@inheritdoc} 58 | */ 59 | protected function fetchObjectFromCache($key) 60 | { 61 | if (null === $data = $this->store->get($this->getHierarchyKey($key))) { 62 | return [false, null, [], null]; 63 | } 64 | 65 | return unserialize($data); 66 | } 67 | 68 | /** 69 | * {@inheritdoc} 70 | */ 71 | protected function clearAllObjectsFromCache() 72 | { 73 | return $this->store->flush(); 74 | } 75 | 76 | /** 77 | * {@inheritdoc} 78 | */ 79 | protected function clearOneObjectFromCache($key) 80 | { 81 | $path = null; 82 | $keyString = $this->getHierarchyKey($key, $path); 83 | if ($path) { 84 | if ($this->store->get($path) === null) { 85 | $this->store->put($path, 0, 0); 86 | } 87 | $this->store->increment($path); 88 | } 89 | $this->clearHierarchyKeyCache(); 90 | 91 | return $this->store->forget($keyString); 92 | } 93 | 94 | /** 95 | * {@inheritdoc} 96 | */ 97 | protected function getList($name) 98 | { 99 | $list = $this->store->get($name); 100 | 101 | if (!is_array($list)) { 102 | return []; 103 | } 104 | 105 | return $list; 106 | } 107 | 108 | /** 109 | * {@inheritdoc} 110 | */ 111 | protected function removeList($name) 112 | { 113 | return $this->store->forget($name); 114 | } 115 | 116 | /** 117 | * {@inheritdoc} 118 | */ 119 | protected function appendListItem($name, $key) 120 | { 121 | $list = $this->getList($name); 122 | $list[] = $key; 123 | 124 | $this->store->forever($name, $list); 125 | } 126 | 127 | /** 128 | * {@inheritdoc} 129 | */ 130 | protected function removeListItem($name, $key) 131 | { 132 | $list = $this->getList($name); 133 | 134 | foreach ($list as $i => $item) { 135 | if ($item === $key) { 136 | unset($list[$i]); 137 | } 138 | } 139 | 140 | $this->store->forever($name, $list); 141 | } 142 | 143 | /** 144 | * {@inheritdoc} 145 | */ 146 | public function getDirectValue($name) 147 | { 148 | return $this->store->get($name); 149 | } 150 | } 151 | --------------------------------------------------------------------------------