Skip to content

Commit

Permalink
Added support to remember forever cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
gent-fella-health committed Nov 25, 2020
1 parent 45edcf0 commit 9399529
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ GOOGLE_SERVICE_ACCOUNT_JSON_LOCATION=
laravel_cache' => [
'enable' => true,
'driver' => 'file',
'remember_in_seconds' => 600
'remember_forever' => false,
'remember_in_seconds' => 600 // 10 minutes
]
```

Expand Down
1 change: 1 addition & 0 deletions src/Config/larasheets.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
'laravel_cache' => [
'enable' => true,
'driver' => 'file',
'remember_forever' => false,
'remember_in_seconds' => 600
]
];
19 changes: 16 additions & 3 deletions src/Services/LarasheetsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ public function getAll($except = [])
return $allRows;
}

return Cache::store(config('larasheets.laravel_cache.driver'))->remember('larasheets.'. $this->spreadsheetId. $this->sheetName, config('larasheets.laravel_cache.remember_in_seconds'), function () use ($allRows) {
return $allRows;
});
return $this->addFileInCache($allRows);
}

public function getByRange($range)
Expand Down Expand Up @@ -148,6 +146,21 @@ public function removeFileInCache()
return Cache::store(config('larasheets.laravel_cache.driver'))->forget('larasheets.'. $this->spreadsheetId. $this->sheetName);
}

public function addFileInCache($allRows)
{
$key = 'larasheets.'. $this->spreadsheetId. $this->sheetName;

$closure = function () use ($allRows) {
return $allRows;
};

if (config('larasheets.laravel_cache.remember_forever')) {
return Cache::store(config('larasheets.laravel_cache.driver'))->rememberForever($key, $closure);
}

return Cache::store(config('larasheets.laravel_cache.driver'))->remember($key, config('larasheets.laravel_cache.remember_in_seconds'), $closure);
}

public function parseData($data, $except)
{
$collection = collect($data);
Expand Down

0 comments on commit 9399529

Please sign in to comment.