Skip to content

Commit 606de96

Browse files
committed
Updated README to reflect latest changes
1 parent f2811b0 commit 606de96

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

README.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,15 @@ Cache::set('my_cache_key_2', 'my second value', 3600);
2828
Cache::set('my_cache_key_3', ['obj' => 'value']);
2929

3030
// Getting data from cache
31-
// Definition: get($key, $default = null)
31+
// Definition: get($key, $fallback = null)
3232
Cache::get('my_cache_key');
33-
Cache::get('my_non_existing_key', 'default/fallback value');
33+
Cache::get('my_non_existing_key', 'fallback value');
34+
// The $fallback parameter also allows for callables
35+
Cache::get('my_non_existing_key', 'MyClass::myCallbackMethod');
36+
Cache::get('my_non_existing_key', ['MyClass', 'myCallbackMethod']);
37+
Cache::get('my_non_existing_key', function(){
38+
return 'fallback value';
39+
});
3440

3541
// Manually removing data from cache
3642
// Definition: remove($key)
@@ -45,17 +51,14 @@ Cache::prune();
4551
// Here's an example:
4652
function getRecordFromDatabase($id)
4753
{
48-
if ($cachedValue = Cache::magicGet()) {
49-
return $cachedValue;
50-
}
51-
52-
$value = fetchValueFromDatabase($id); // replace this with your own data fetching/processing code
53-
54-
return Cache::magicSet($value);
54+
return Cache::magicGet([], function() use ($id) {
55+
$value = fetchValueFromDatabase($id); // replace this with your own data fetching/processing code
56+
return Cache::magicSet($value);
57+
});
5558
}
5659

5760
// The definition of both methods goes as follows:
58-
// magicGet($suffixes = [], $default = null)
61+
// magicGet($fallback = null, $suffixes = [])
5962
// magicSet($value, $expiresAfter = 0, $suffixes = [])
6063
```
6164

0 commit comments

Comments
 (0)