Skip to content

Commit efc511f

Browse files
committed
Updated readme and license
1 parent c155e00 commit efc511f

File tree

3 files changed

+58
-45
lines changed

3 files changed

+58
-45
lines changed

LICENSE

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
MIT License
1+
The MIT License (MIT)
22

3-
Copyright (c) 2018 rennokki
3+
Copyright (c) Renoki Co.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal
@@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99
copies of the Software, and to permit persons to whom the Software is
1010
furnished to do so, subject to the following conditions:
1111

12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
1414

1515
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1717
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
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.
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

LICENSE.md

Lines changed: 0 additions & 21 deletions
This file was deleted.

README.md

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,18 @@ Laravel Eloquent Query Cache
99
[![Monthly Downloads](https://poser.pugx.org/rennokki/laravel-eloquent-query-cache/d/monthly)](https://packagist.org/packages/rennokki/laravel-eloquent-query-cache)
1010
[![License](https://poser.pugx.org/rennokki/laravel-eloquent-query-cache/license)](https://packagist.org/packages/rennokki/laravel-eloquent-query-cache)
1111

12-
[![PayPal](https://img.shields.io/badge/PayPal-donate-blue.svg)](https://paypal.me/rennokki)
13-
14-
Laravel Eloquent Query Cache (LEQC; Le QC; Le Query Cache) is a package that brings the `remember()` functionality that has been removed from Laravel a long time ago.
15-
This package helps adding caching functionalities directly on the Eloquent level, making use of cache before retrieving the data from the DB.
16-
17-
This package adds caching support for **all** query methods.
12+
Laravel Eloquent Query Cache brings back the `remember()` functionality that has been removed from Laravel a long time ago.
13+
It adds caching functionalities directly on the Eloquent level, making use of cache within your database queries.
1814

1915
## Installing the package
16+
2017
Hop into your console and install the package via Composer:
2118

2219
```bash
2320
$ composer require rennokki/laravel-eloquent-query-cache
2421
```
2522

26-
Each model that will accept query-by-query caching will have to use the `Rennokki\QueryCache\Traits\QueryCacheable` trait.
23+
Each model you want cache on should use the `Rennokki\QueryCache\Traits\QueryCacheable` trait.
2724

2825
```php
2926
use Rennokki\QueryCache\Traits\QueryCacheable;
@@ -37,7 +34,9 @@ class Podcast extends Model
3734
```
3835

3936
## Showcase
40-
Query Cache has the ability to track the SQL used and use it as a key in the cache storage, making the caching query-by-query a breeze.
37+
38+
The package has the ability to track the SQL used and use it as a key in the cache storage,
39+
making the caching query-by-query a breeze.
4140

4241
```php
4342
use Rennokki\QueryCache\Traits\QueryCacheable;
@@ -57,9 +56,9 @@ $latestArticle = Article::latest()->first();
5756
$publishedArticles = Article::wherePublished(true)->get();
5857
```
5958

60-
In the above example, both queries have different keys in the cache storage, thus it doesn't matter what query we handle. By default, caching is disabled unless specifying a value for `$cacheFor`. As long as `$cacheFor` is existent and is greater than `0`, all queries will be cached.
59+
In the above example, both queries have different keys in the cache storage, thus it doesn't matter what query we handle. By default, caching is disabled unless you specify a value for `$cacheFor`. As long as `$cacheFor` is existent and is greater than `0`, all queries will be cached.
6160

62-
It is also possible to enable caching for specific queries. This is the recommended way because it is easier to manage each query.
61+
It is also possible to enable caching for specific queries by not specifying `$cacheFor` and calling `cacheFor()` within your queries:
6362

6463
```php
6564
$postsCount = Post::cacheFor(60 * 60)->count();
@@ -69,11 +68,19 @@ $postsCount = Post::cacheFor(now()->addDays(1))->count();
6968
```
7069

7170
## Cache Tags & Cache Invalidation
71+
7272
Some caching stores accept tags. This is really useful if you plan on tagging your cached queries and invalidate only some of the queries when needed.
7373

7474
```php
75-
$shelfOneBooks = Book::whereShelf(1)->cacheFor(60)->cacheTags(['shelf:1'])->get();
76-
$shelfTwoBooks = Book::whereShelf(2)->cacheFor(60)->cacheTags(['shelf:2'])->get();
75+
$shelfOneBooks = Book::whereShelf(1)
76+
->cacheFor(60)
77+
->cacheTags(['shelf:1'])
78+
->get();
79+
80+
$shelfTwoBooks = Book::whereShelf(2)
81+
->cacheFor(60)
82+
->cacheTags(['shelf:2'])
83+
->get();
7784

7885
// After flushing the cache for shelf:1, the query of$shelfTwoBooks will still hit the cache if re-called again.
7986
Book::flushQueryCache(['shelf:1']);
@@ -86,8 +93,15 @@ Be careful tho - specifying cache tags does not change the behaviour of key stor
8693
For example, the following two queries, altough the use the same tag, they have different keys stored in the caching database.
8794

8895
```php
89-
$alice = Kid::whereName('Alice')->cacheFor(60)->cacheTags(['kids'])->first();
90-
$bob = Kid::whereName('Bob')->cacheFor(60)->cacheTags(['kids'])->first();
96+
$alice = Kid::whereName('Alice')
97+
->cacheFor(60)
98+
->cacheTags(['kids'])
99+
->first();
100+
101+
$bob = Kid::whereName('Bob')
102+
->cacheFor(60)
103+
->cacheTags(['kids'])
104+
->first();
91105
```
92106

93107
### Global Cache Invalidation
@@ -122,41 +136,55 @@ Kid::flushQueryCache();
122136
```
123137

124138
## Relationship Caching
139+
125140
Relationships are just another queries. They can be intercepted and modified before the database is hit with the query. The following example needs the `Order` model (or the model associated with the `orders` relationship) to include the `QueryCacheable` trait.
126141

127142
```php
128143
$user = User::with(['orders' => function ($query) {
129-
return $query->cacheFor(60 * 60)->cacheTags(['my:orders']);
144+
return $query
145+
->cacheFor(60 * 60)
146+
->cacheTags(['my:orders']);
130147
}])->get();
131148

132149
// This comes from the cache if existed.
133150
$orders = $user->orders;
134151
```
135152

136153
## Cache Keys
154+
137155
The package automatically generate the keys needed to store the data in the cache store. However, prefixing them might be useful if the cache store is used by other applications and/or models and you want to manage the keys better to avoid collisions.
138156

139157
```php
140-
$bob = Kid::whereName('Bob')->cacheFor(60)->cachePrefix('kids_')->first();
158+
$bob = Kid::whereName('Bob')
159+
->cacheFor(60)
160+
->cachePrefix('kids_')
161+
->first();
141162
```
142163

143164
If no prefix is specified, the string `leqc` is going to be used.
144165

145166
## Cache Drivers
167+
146168
By default, the trait uses the default cache driver. If you want to **force** a specific one, you can do so by calling `cacheDriver()`:
147169

148170
```php
149-
$bob = Kid::whereName('Bob')->cacheFor(60)->cacheDriver('dynamodb')->first();
171+
$bob = Kid::whereName('Bob')
172+
->cacheFor(60)
173+
->cacheDriver('dynamodb')
174+
->first();
150175
```
151176

152177
## Disable caching
153-
If you enabled caching (either by model variable or by the `cacheFor` scope), you can also opt to disable it mid-builder.
178+
179+
If you enabled caching (either by model variable or by the `cacheFor` scope), you can also opt to disable it within your query builder chains:
180+
154181
```php
155182
$uncachedBooks = Book::dontCache()->get();
156183
$uncachedBooks = Book::doNotCache()->get(); // same thing
157184
```
158185

159186
## Equivalent Methods and Variables
187+
160188
You can use the methods provided in this documentation query-by-query, or you can set defaults for each one in the model; using the methods query-by-query will overwrite the defaults.
161189
While settings defaults is not mandatory (excepting for `$cacheFor` that will enable caching on **all** queries), it can be useful to avoid using the chained methods on each query.
162190

@@ -174,6 +202,7 @@ class Book extends Model
174202
```
175203

176204
## Implement the caching method to your own Builder class
205+
177206
Since this package modifies the `newBaseQueryBuilder()` in the model, having multiple traits that
178207
modify this function will lead to an overlap.
179208

@@ -215,7 +244,9 @@ CustomModel::cacheFor(30)->customGetMethod();
215244
```
216245

217246
## Generating your own key
247+
218248
This is how the default key generation function looks like:
249+
219250
```php
220251
public function generatePlainCacheKey(string $method = 'get', $id = null, $appends = null): string
221252
{
@@ -251,7 +282,9 @@ class MyCustomBuilder implements QueryCacheModuleInterface
251282
```
252283

253284
## Implementing cache for other functions than get()
285+
254286
Since all of the Laravel Eloquent functions are based on it, the builder that comes with this package replaces only the `get()` one:
287+
255288
```php
256289
class Builder
257290
{
@@ -267,6 +300,7 @@ class Builder
267300
```
268301

269302
In case that you want to cache your own methods from your custom builder or, for instance, your `count()` method doesn't rely on `get()`, you can replace it using this syntax:
303+
270304
```php
271305
class MyCustomBuilder
272306
{

0 commit comments

Comments
 (0)