Skip to content

Commit 46643a0

Browse files
authored
Merge pull request #76 from andrewmclagan/feature/without-session-driver
Removing session driver dependancy, using cache
2 parents 5629be0 + 32d5fed commit 46643a0

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/Traits/Cachable.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use GeneaLabs\LaravelModelCaching\CacheKey;
44
use GeneaLabs\LaravelModelCaching\CacheTags;
55
use GeneaLabs\LaravelModelCaching\CachedModel;
6+
use Illuminate\Support\Facades\Cache;
67
use Illuminate\Cache\TaggableStore;
78
use Illuminate\Database\Query\Builder;
89
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
@@ -12,6 +13,8 @@ trait Cachable
1213
{
1314
protected $isCachable = true;
1415

16+
protected static $isCachableKey = 'genealabs:model-caching:is-disabled';
17+
1518
protected function cache(array $tags = [])
1619
{
1720
$cache = cache();
@@ -33,7 +36,8 @@ protected function cache(array $tags = [])
3336

3437
public function disableCache()
3538
{
36-
session(['genealabs-laravel-model-caching-is-disabled' => true]);
39+
Cache::forever(static::$isCachableKey, true);
40+
3741
$this->isCachable = false;
3842

3943
return $this;
@@ -78,9 +82,9 @@ public static function bootCachable()
7882

7983
public static function all($columns = ['*'])
8084
{
81-
if (session('genealabs-laravel-model-caching-is-disabled')) {
85+
if (Cache::get(static::$isCachableKey)) {
8286
return parent::all($columns);
83-
}
87+
}
8488

8589
$class = get_called_class();
8690
$instance = new $class;
@@ -95,8 +99,8 @@ public static function all($columns = ['*'])
9599

96100
public function newEloquentBuilder($query)
97101
{
98-
if (session('genealabs-laravel-model-caching-is-disabled')) {
99-
session()->forget('genealabs-laravel-model-caching-is-disabled');
102+
if (Cache::get(static::$isCachableKey)) {
103+
Cache::forget(static::$isCachableKey);
100104

101105
return new EloquentBuilder($query);
102106
}

0 commit comments

Comments
 (0)