https://github.com/themeplate/cache
Convenient fragment caching methods
https://github.com/themeplate/cache
cache wordpress wordpress-cache
Last synced: 10 months ago
JSON representation
Convenient fragment caching methods
- Host: GitHub
- URL: https://github.com/themeplate/cache
- Owner: ThemePlate
- License: gpl-3.0
- Created: 2020-01-27T01:29:20.000Z (almost 6 years ago)
- Default Branch: develop
- Last Pushed: 2025-03-01T07:54:41.000Z (10 months ago)
- Last Synced: 2025-03-01T08:24:31.649Z (10 months ago)
- Topics: cache, wordpress, wordpress-cache
- Language: PHP
- Homepage:
- Size: 74.2 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ThemePlate Cache
## Usage
```php
use ThemePlate\Cache;
Cache::remember( 'unique_key', function() {
return expensive_task();
}, MINUTE_IN_SECONDS );
Cache::forget( 'unique_key' );
Cache::file( 'special_key', 'path_to_file' );
$processor = Cache::processor();
$processor->report( function( $output ) {
error_log( print_r( $output, true ) );
} );
function hourly_moment() {
return 'to remember ' . time();
}
Cache::remember( 'unique_key', 'hourly_moment', HOUR_IN_SECONDS );
```
### Force refresh value/s
`/?tcs_refresh=`
`/?tcs_refresh[]=&tcs_refresh[]=`
> _works only when logged-in_
### Cache::remember( $key, $callback, $expiration )
Retrieve content from the cache or, if it doesn't exist, execute $callback and its result is returned then saved
- **$key** _(string)(Required)_ Unique cache key to use
- **$callback** _(callable)(Required)_ Function that returns data to store
- **$expiration** _(int)(Optional)_ Number of seconds before entry expires. Default 0 (forever)
### Cache::forget( $key, $default )
Retrieve and delete the cache
- **$key** _(string)(Required)_ Unique cache key to use
- **$default** _(mixed)(Optional)_ To return if cache doesn't exist. Default `null`
### Cache::file( $key, $path )
Like `remember` but, uses the file contents and no expiration, automatically updates if the file is modified instead
- **$key** _(string)(Required)_ Unique cache key to use
- **$path** _(string)(Required)_ Path of the file to read
### Cache::processor()
Support for soft-expiration, `Cache::remember`\* and `Cache::file` updates in the background
> \*Except for using anonymous function as callback (closure)