File tree 3 files changed +37
-45
lines changed 3 files changed +37
-45
lines changed Original file line number Diff line number Diff line change @@ -10,8 +10,6 @@ class CachedBuilder extends EloquentBuilder
10
10
{
11
11
use Cachable;
12
12
13
- protected $ isCachable = true ;
14
-
15
13
public function avg ($ column )
16
14
{
17
15
if (! $ this ->isCachable ) {
@@ -56,13 +54,6 @@ public function delete()
56
54
return parent ::delete ();
57
55
}
58
56
59
- public function disableCache ()
60
- {
61
- $ this ->isCachable = false ;
62
-
63
- return $ this ;
64
- }
65
-
66
57
/**
67
58
* @SuppressWarnings(PHPMD.ShortVariable)
68
59
*/
@@ -155,16 +146,4 @@ public function sum($column)
155
146
return parent ::sum ($ column );
156
147
});
157
148
}
158
-
159
- protected function makeCacheKey (array $ columns = ['* ' ], $ idColumn = null ) : string
160
- {
161
- return (new CacheKey ($ this ->eagerLoad , $ this ->model , $ this ->query ))
162
- ->make ($ columns , $ idColumn );
163
- }
164
-
165
- protected function makeCacheTags () : array
166
- {
167
- return (new CacheTags ($ this ->eagerLoad , $ this ->model ))
168
- ->make ();
169
- }
170
149
}
Original file line number Diff line number Diff line change 1
1
<?php namespace GeneaLabs \LaravelModelCaching ;
2
2
3
3
use GeneaLabs \LaravelModelCaching \CachedBuilder as Builder ;
4
+ use GeneaLabs \LaravelModelCaching \Traits \Cachable ;
4
5
use Illuminate \Cache \CacheManager ;
5
6
use Illuminate \Cache \TaggableStore ;
6
7
use Illuminate \Cache \TaggedCache ;
12
13
13
14
abstract class CachedModel extends Model
14
15
{
16
+ use Cachable;
17
+
15
18
public function newEloquentBuilder ($ query )
16
19
{
17
20
if (session ('genealabs-laravel-model-caching-is-disabled ' )) {
@@ -46,30 +49,6 @@ public static function boot()
46
49
});
47
50
}
48
51
49
- public function cache (array $ tags = [])
50
- {
51
- $ cache = cache ();
52
-
53
- if (is_subclass_of ($ cache ->getStore (), TaggableStore::class)) {
54
- array_push ($ tags , str_slug (get_called_class ()));
55
- $ cache = $ cache ->tags ($ tags );
56
- }
57
-
58
- return $ cache ;
59
- }
60
-
61
- public function disableCache () : self
62
- {
63
- session (['genealabs-laravel-model-caching-is-disabled ' => true ]);
64
-
65
- return $ this ;
66
- }
67
-
68
- public function flushCache (array $ tags = [])
69
- {
70
- $ this ->cache ($ tags )->flush ();
71
- }
72
-
73
52
public static function all ($ columns = ['* ' ])
74
53
{
75
54
$ class = get_called_class ();
Original file line number Diff line number Diff line change 1
1
<?php namespace GeneaLabs \LaravelModelCaching \Traits ;
2
2
3
+ use GeneaLabs \LaravelModelCaching \CacheKey ;
4
+ use GeneaLabs \LaravelModelCaching \CacheTags ;
5
+ use GeneaLabs \LaravelModelCaching \CachedModel ;
3
6
use Illuminate \Cache \TaggableStore ;
4
7
5
8
trait Cachable
6
9
{
10
+ protected $ isCachable = true ;
11
+
7
12
protected function cache (array $ tags = [])
8
13
{
9
14
$ cache = cache ();
10
15
11
16
if (is_subclass_of ($ cache ->getStore (), TaggableStore::class)) {
17
+ if (is_a ($ this , CachedModel::class)) {
18
+ array_push ($ tags , str_slug (get_called_class ()));
19
+ }
20
+
12
21
$ cache = $ cache ->tags ($ tags );
13
22
}
14
23
15
24
return $ cache ;
16
25
}
26
+
27
+ public function disableCache ()
28
+ {
29
+ session (['genealabs-laravel-model-caching-is-disabled ' => true ]);
30
+ $ this ->isCachable = false ;
31
+
32
+ return $ this ;
33
+ }
34
+
35
+ public function flushCache (array $ tags = [])
36
+ {
37
+ $ this ->cache ($ tags )->flush ();
38
+ }
39
+
40
+ protected function makeCacheKey (array $ columns = ['* ' ], $ idColumn = null ) : string
41
+ {
42
+ return (new CacheKey ($ this ->eagerLoad , $ this ->model , $ this ->query ))
43
+ ->make ($ columns , $ idColumn );
44
+ }
45
+
46
+ protected function makeCacheTags () : array
47
+ {
48
+ return (new CacheTags ($ this ->eagerLoad , $ this ->model ))
49
+ ->make ();
50
+ }
17
51
}
You can’t perform that action at this time.
0 commit comments