|
1 | | -## Cache Modification helper |
| 1 | +## Laravel Cache |
2 | 2 |
|
3 | | -### IMPORTANT! |
4 | | -#### The package is no longer supported. To implement caching, use the [GeneaLabs/laravel-model-caching](https://github.com/GeneaLabs/laravel-model-caching) package. |
5 | | - |
6 | | - |
7 | | -Cache helper for the [Illuminate Cache](https://github.com/illuminate/cache) package. |
8 | | - |
9 | | - |
10 | | - |
11 | | -<p align="center"> |
12 | | - <a href="https://styleci.io/repos/119809288"><img src="https://styleci.io/repos/119809288/shield" alt="StyleCI" /></a> |
13 | | - <a href="https://packagist.org/packages/andrey-helldar/cache"><img src="https://img.shields.io/packagist/dt/andrey-helldar/cache.svg?style=flat-square" alt="Total Downloads" /></a> |
14 | | - <a href="https://packagist.org/packages/andrey-helldar/cache"><img src="https://poser.pugx.org/andrey-helldar/cache/v/stable?format=flat-square" alt="Latest Stable Version" /></a> |
15 | | - <a href="https://packagist.org/packages/andrey-helldar/cache"><img src="https://poser.pugx.org/andrey-helldar/cache/v/unstable?format=flat-square" alt="Latest Unstable Version" /></a> |
16 | | - <a href="LICENSE"><img src="https://poser.pugx.org/andrey-helldar/cache/license?format=flat-square" alt="License" /></a> |
17 | | -</p> |
| 3 | +<img src="https://preview.dragon-code.pro/TheDragonCode/laravel-cache.svg?brand=laravel" alt="Laravel Cache"/> |
18 | 4 |
|
| 5 | +[![Stable Version][badge_stable]][link_packagist] |
| 6 | +[![Unstable Version][badge_unstable]][link_packagist] |
| 7 | +[![Total Downloads][badge_downloads]][link_packagist] |
| 8 | +[![License][badge_license]][link_license] |
19 | 9 |
|
20 | 10 | ## Installation |
21 | 11 |
|
22 | | -To get the latest version of Cache Modification, simply require the project using [Composer](https://getcomposer.org/): |
| 12 | +To get the latest version of `Laravel Cache`, simply require the project using [Composer](https://getcomposer.org): |
23 | 13 |
|
24 | 14 | ```bash |
25 | | -$ composer require andrey-helldar/cache |
| 15 | +$ composer require dragon-code/laravel-cache |
26 | 16 | ``` |
27 | 17 |
|
28 | | -Instead, you may of course manually update your require block and run `composer update` if you so choose: |
| 18 | +Or manually update `require` block of `composer.json` and run `composer update`. |
29 | 19 |
|
30 | 20 | ```json |
31 | 21 | { |
32 | 22 | "require": { |
33 | | - "andrey-helldar/cache": "^1.0" |
| 23 | + "dragon-code/laravel-cache": "^2.0" |
34 | 24 | } |
35 | 25 | } |
36 | 26 | ``` |
37 | 27 |
|
38 | | -Once installed, you need to register the `Helldar\Cache\ServiceProvider::class` service provider in your `config/app.php`, or if you're using Laravel 5.5, this can be done via the automatic package discovery. |
| 28 | +## Using |
| 29 | + |
| 30 | +### When True |
| 31 | + |
| 32 | +#### Basic |
| 33 | + |
| 34 | +By default, the cache will be written for 1 day. |
| 35 | + |
| 36 | +```php |
| 37 | +use DragonCode\Cache\Services\Cache; |
| 38 | + |
| 39 | +$cache = Cache::make()->key('foo', 'bar', ['baz', 'baq']); |
| 40 | + |
| 41 | +$cache->put(static fn() => 'Some value'); |
| 42 | +// Contains cached `Some value` |
| 43 | + |
| 44 | +$cache->get(); |
| 45 | +// Returns cached `Some value` |
| 46 | + |
| 47 | +$cache->has(); |
| 48 | +// Returns `true` |
| 49 | + |
| 50 | +$cache->forget(); |
| 51 | +// Will remove the key from the cache. |
| 52 | +``` |
| 53 | + |
| 54 | +#### Custom TTL |
| 55 | + |
| 56 | +The cache will be written for the specified number of minutes. |
| 57 | + |
| 58 | +```php |
| 59 | +use DragonCode\Cache\Services\Cache; |
| 60 | + |
| 61 | +$cache = Cache::make() |
| 62 | + ->ttl($minutes) |
| 63 | + ->key('foo', 'bar', ['baz', 'baq']); |
| 64 | + |
| 65 | +$cache->put(static fn() => 'Some value'); |
| 66 | +// Contains cached `Some value` |
| 67 | + |
| 68 | +$cache->get(); |
| 69 | +// Returns cached `Some value` |
| 70 | + |
| 71 | +$cache->has(); |
| 72 | +// Returns `true` |
| 73 | + |
| 74 | +$cache->forget(); |
| 75 | +// Will remove the key from the cache. |
| 76 | +``` |
| 77 | + |
| 78 | +#### Tagged |
39 | 79 |
|
| 80 | +For repositories that support tagging, the keys will be saved separated by tags. |
40 | 81 |
|
41 | | -## How to use |
| 82 | +```php |
| 83 | +use DragonCode\Cache\Services\Cache; |
| 84 | + |
| 85 | +$cache = Cache::make() |
| 86 | + ->tags('actor', 'author') |
| 87 | + ->key('foo', 'bar', ['baz', 'baq']); |
| 88 | + |
| 89 | +$cache->put(static fn() => 'Some value'); |
| 90 | +// Contains cached `Some value` |
| 91 | + |
| 92 | +$cache->get(); |
| 93 | +// Returns cached `Some value` |
| 94 | + |
| 95 | +$cache->has(); |
| 96 | +// Returns `true` |
| 97 | + |
| 98 | +$cache->forget(); |
| 99 | +// Will remove the key from the cache. |
| 100 | +``` |
| 101 | + |
| 102 | +To retrieve a tagged cache item, pass the same ordered list of tags to the tags method and then call the get method with the key you wish to retrieve: |
42 | 103 |
|
43 | 104 | ```php |
44 | | -return cache_mod() |
45 | | - ->key('it', 'is', 'a', 'key') |
46 | | - ->minutes(60) |
47 | | - ->tags('it', 'is', 'a', 'tags') |
48 | | - ->remember(function() { |
49 | | - return 'my value'; |
50 | | - }); |
51 | | - |
52 | | -return cache_mod() |
53 | | - ->key('it', 'is', 'a', 'key') |
54 | | - ->remember(function() { |
55 | | - return 'my value'; |
56 | | - }); |
| 105 | +use DragonCode\Cache\Services\Cache; |
| 106 | + |
| 107 | +$cache = Cache::make() |
| 108 | + ->key('foo', 'bar'); |
| 109 | + |
| 110 | +$cache->tags('actor', 'author')->put(static fn() => 'Some value'); |
| 111 | +// Contains cached `Some value` |
| 112 | + |
| 113 | +$cache->tags('actor', 'author')->get(); |
| 114 | +// Returns cached `Some value` |
| 115 | + |
| 116 | +$cache->tags('actor')->get(); |
| 117 | +// Returns `null` |
| 118 | + |
| 119 | +$cache->tags('author')->get(); |
| 120 | +// Returns `null` |
57 | 121 | ``` |
58 | 122 |
|
59 | | -To disable the caching, you need to set the `CACHE_DRIVER=array` in `.env`. |
| 123 | +> See the official Laravel [documentation](https://laravel.com/docs/cache#accessing-tagged-cache-items). |
| 124 | +
|
| 125 | +## License |
| 126 | + |
| 127 | +This package's licensed under the [MIT License](LICENSE). |
| 128 | + |
60 | 129 |
|
| 130 | +[badge_downloads]: https://img.shields.io/packagist/dt/dragon-code/laravel-cache.svg?style=flat-square |
61 | 131 |
|
62 | | -## Copyright and License |
| 132 | +[badge_license]: https://img.shields.io/packagist/l/dragon-code/laravel-cache.svg?style=flat-square |
63 | 133 |
|
64 | | -Cache Modification for [Illuminate Cache](https://github.com/illuminate/cache) package was written by Andrey Helldar for the Laravel framework 5.4 or above, and is released under the MIT License. See the [LICENSE](LICENSE) file for details. |
| 134 | +[badge_stable]: https://img.shields.io/github/v/release/dragon-code/laravel-cache?label=stable&style=flat-square |
65 | 135 |
|
| 136 | +[badge_unstable]: https://img.shields.io/badge/unstable-dev--main-orange?style=flat-square |
66 | 137 |
|
67 | | -## Translation |
| 138 | +[link_license]: LICENSE |
68 | 139 |
|
69 | | -Translations of text and comment by Google Translate. Help with translation +1 in karma :) |
| 140 | +[link_packagist]: https://packagist.org/packages/dragon-code/laravel-cache |
0 commit comments