diff options
author | 2022-04-03 12:19:13 +0200 | |
---|---|---|
committer | 2022-04-03 12:19:13 +0200 | |
commit | d3bb00f754f8b1b0d8b8ec2e839eb622e54b5266 (patch) | |
tree | f1d52c6366c0e705916693c4bec07cf8ef7c693e | |
parent | 00a3f80ac4842e87d150a84c5040f60928dc3380 (diff) | |
download | rss-bridge-d3bb00f754f8b1b0d8b8ec2e839eb622e54b5266.tar.gz rss-bridge-d3bb00f754f8b1b0d8b8ec2e839eb622e54b5266.tar.zst rss-bridge-d3bb00f754f8b1b0d8b8ec2e839eb622e54b5266.zip |
docs: Explain loadCacheValue and saveCacheValue
This adds documentation for methods added via #1380.
-rw-r--r-- | docs/05_Bridge_API/02_BridgeAbstract.md | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/docs/05_Bridge_API/02_BridgeAbstract.md b/docs/05_Bridge_API/02_BridgeAbstract.md index e61c8c7c..57c27889 100644 --- a/docs/05_Bridge_API/02_BridgeAbstract.md +++ b/docs/05_Bridge_API/02_BridgeAbstract.md @@ -453,4 +453,62 @@ public function detectParameters($url){ return null; } } -```
\ No newline at end of file +``` + +*** + +# Helper Methods +`BridgeAbstract` implements helper methods to make it easier for bridge maintainers to create bridges. Use these methods whenever possible instead of writing your own. + +- [saveCacheValue](#savecachevalue) +- [loadCacheValue](#loadcachevalue) + +## saveCacheValue +Within the context of the current bridge, stores a value by key in the cache. The value can later be retrieved with [loadCacheValue](#loadcachevalue). + +```php +protected function saveCacheValue($key, $value) +``` + +- `$key` - the name under which the value is stored in the cache. +- `$value` - the value to store in the cache. + +Usage example: + +```php +const MY_KEY = 'MyKey'; + +public function collectData() +{ + $value = 'my value'; + $this->saveCacheValue(MY_KEY, $value); +} +``` + +## loadCacheValue +Within the context of the current bridge, loads a value by key from cache. Optionally specifies the cache duration for the key. Returns `null` if the key doesn't exist or the value is expired. + +```php +protected function loadCacheValue($key, $duration = 86400) +``` + +- `$key` - the name under which the value is stored in the cache. +- `$duration` - the maximum time in seconds after which the value expires. The default duration is 86400 (24 hours). + +Usage example: + +```php +const MY_KEY = 'MyKey'; + +public function collectData() +{ + $value = $this->loadCacheValue(MY_KEY, 1800 /* 30 minutes */); + + if (!isset($value)){ + // load value + $this->saveCacheValue(MY_KEY, $value); + } + + // ... +} +``` |