https://github.com/stscoundrel/svangr
Programmatic cache for WP
https://github.com/stscoundrel/svangr
cache php psr-16 transients
Last synced: 4 months ago
JSON representation
Programmatic cache for WP
- Host: GitHub
- URL: https://github.com/stscoundrel/svangr
- Owner: stscoundrel
- License: mit
- Created: 2020-05-10T20:03:07.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-08-02T15:40:29.000Z (almost 5 years ago)
- Last Synced: 2023-09-17T12:14:28.302Z (almost 2 years ago)
- Topics: cache, php, psr-16, transients
- Language: PHP
- Homepage:
- Size: 14.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Svangr
Programmatic cache for WP. Implements [PSR16 cache interface](https://www.php-fig.org/psr/psr-16/).## Install
Via Composer:
`composer require silvanus/svangr`
To use autoloading mechanism, you must include `vendor/autoload.php` file in your code.
## Usage.
Currently has one strategy: transients.
### Transient
Working with transients in WP can be a bit awkward and lead to lot of boilerplate code. Svangr offers simple api to work with transients.
#### Set / Get / Delete
```php
has('myStuff'); // true / false.// Set individual value.
$cache->set('myStuff', myTimeConsumingFunction());// Set individual value with refresh time -> defaults to 60 minutes if empty.
$cache->set('willBeGoneInFiveMinutes', myFiveMinuteStuff(), 300)// Get individual value.
$cache->get('myStuff');// Delete individual value.
$cache->delete('myStuff'):```
#### Working with multiple values
```php
setMultiple( array( 'events' => myFoo(), 'items' => myBar(), 'resources' => myBaz() ) );// Get many values. Returned as key => value array.
$cache->getMultiple( 'events', 'items', 'resources' );// Delete multiple values.
$cache->deleteMultiple( array( 'events', 'items', 'resources' ) ):```
### Clearing all transients
```php
clear();```
## Whats in the name?
["Svangr"](https://en.wiktionary.org/wiki/svangr) is [Old Norse](https://en.wikipedia.org/wiki/Old_Norse) word for "hungry" or "thin". Caches are hungry, and this is implementation is a thin abstraction.