-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add rememberWithTags method for easier usage
- Loading branch information
Showing
3 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Anorgan\LaravelCache; | ||
|
||
use \AlternativeLaravelCache\Store\AlternativeRedisCacheStore as BaseAlternativeRedisCacheStore; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Support\Collection; | ||
|
||
class AlternativeRedisCacheStore extends BaseAlternativeRedisCacheStore | ||
{ | ||
/** | ||
* @param $key | ||
* @param $minutes | ||
* @param Closure $callback | ||
* @param array $tags | ||
*/ | ||
public function rememberWithTags($key, $minutes, \Closure $callback, array $tags = []) | ||
{ | ||
// If the item exists in the cache we will just return this immediately | ||
// otherwise we will execute the given Closure and cache the result | ||
// of that execution for the given number of minutes in storage. | ||
if (! is_null($value = $this->get($key))) { | ||
return $value; | ||
} | ||
|
||
$value = $callback(); | ||
|
||
if ($value instanceof Collection || $value instanceof Model) { | ||
$tags = array_merge(app(TagFinder::class)->find($value), $tags); | ||
} | ||
|
||
$this | ||
->tags($tags) | ||
->put($key, $value, $minutes); | ||
|
||
return $value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters