Skip to content

Commit

Permalink
Updated README to reflect latest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilePerron committed Sep 30, 2020
1 parent f2811b0 commit 606de96
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ Cache::set('my_cache_key_2', 'my second value', 3600);
Cache::set('my_cache_key_3', ['obj' => 'value']);

// Getting data from cache
// Definition: get($key, $default = null)
// Definition: get($key, $fallback = null)
Cache::get('my_cache_key');
Cache::get('my_non_existing_key', 'default/fallback value');
Cache::get('my_non_existing_key', 'fallback value');
// The $fallback parameter also allows for callables
Cache::get('my_non_existing_key', 'MyClass::myCallbackMethod');
Cache::get('my_non_existing_key', ['MyClass', 'myCallbackMethod']);
Cache::get('my_non_existing_key', function(){
return 'fallback value';
});

// Manually removing data from cache
// Definition: remove($key)
Expand All @@ -45,17 +51,14 @@ Cache::prune();
// Here's an example:
function getRecordFromDatabase($id)
{
if ($cachedValue = Cache::magicGet()) {
return $cachedValue;
}

$value = fetchValueFromDatabase($id); // replace this with your own data fetching/processing code

return Cache::magicSet($value);
return Cache::magicGet([], function() use ($id) {
$value = fetchValueFromDatabase($id); // replace this with your own data fetching/processing code
return Cache::magicSet($value);
});
}

// The definition of both methods goes as follows:
// magicGet($suffixes = [], $default = null)
// magicGet($fallback = null, $suffixes = [])
// magicSet($value, $expiresAfter = 0, $suffixes = [])
```

Expand Down

0 comments on commit 606de96

Please sign in to comment.