Download the PHP package devuri/ob-cache without Composer
On this page you can find all versions of the php package devuri/ob-cache. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download devuri/ob-cache
More information about devuri/ob-cache
Files in devuri/ob-cache
Package ob-cache
Short Description A simple versatile and easy-to-use PHP class designed for managing caching in WordPress environments.
License MIT
Informations about the package ob-cache
README for the ObCache
Class
Overview
The ObCache
class is a versatile and easy-to-use PHP class designed for caching in WordPress environments. It provides functionality to manage caching operations with ease, supporting operations such as setting, getting, and removing cached data. This class is particularly useful in scenarios where data retrieval from a cache is preferred over repeatedly querying a database or performing complex computations.
Features
- Flexible Caching Control: Control whether caching is enabled or disabled.
- Easy Initialization: Instantiation via a constructor or a static
init
method. - Data Storage and Retrieval: Methods for setting and retrieving cached data.
- Cache Removal: Functionality to remove specific cache entries.
Usage
Instantiation
Directly via constructor:
Using the static init
method:
Setting Cache Mode
Enable or disable caching:
Setting Data in Cache
Use the set
method to cache data:
Retrieving Data from Cache
Use the get
method to retrieve or generate and cache data:
Removing Data from Cache
Use the forget
method to remove data from the cache:
Integration with WordPress
This class utilizes WordPress caching functions (wp_cache_set
, wp_cache_get
, wp_cache_delete
) and is designed to work within a WordPress environment.
Notes
- The class uses a protected constant
OBC_CACHE_GROUP
to define a cache group calledevp_cached
for better organization and management of cached items. - Cache mode status can be checked using
is_cache_allowed()
method. - When caching is disabled, the
set
andget
methods directly handle data without caching.
License
This project is licensed under the MIT License - see the LICENSE file for details.