PHPackages                             devuri/ob-cache - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. devuri/ob-cache

ActiveLibrary[Caching](/categories/caching)

devuri/ob-cache
===============

A simple versatile and easy-to-use PHP class designed for managing caching in WordPress environments.

0.1.0(2y ago)04.0kMITPHPPHP ^7.4 || ^8.0CI passing

Since Dec 17Pushed 2y ago1 watchersCompare

[ Source](https://github.com/devuri/ob-cache)[ Packagist](https://packagist.org/packages/devuri/ob-cache)[ RSS](/packages/devuri-ob-cache/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

README for the `ObCache` Class
==============================

[](#readme-for-the-obcache-class)

Overview
--------

[](#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
--------

[](#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
-----

[](#usage)

### Instantiation

[](#instantiation)

Directly via constructor:

```
$cache = new ObCache();
```

Using the static `init` method:

```
$cache = ObCache::init();
```

### Setting Cache Mode

[](#setting-cache-mode)

Enable or disable caching:

```
$cache->set_cache_allowed(true); // Enable caching
$cache->set_cache_allowed(false); // Disable caching
```

### Setting Data in Cache

[](#setting-data-in-cache)

Use the `set` method to cache data:

```
$cache->set('cache_key', function() {
    // Data generation logic
    return $data;
}, 3600); // 3600 seconds expiration
```

### Retrieving Data from Cache

[](#retrieving-data-from-cache)

Use the `get` method to retrieve or generate and cache data:

```
$data = $cache->get('cache_key', function() {
    // Data generation logic
    return $data;
}, 3600);
```

### Removing Data from Cache

[](#removing-data-from-cache)

Use the `forget` method to remove data from the cache:

```
$cache->forget('cache_key');
```

Integration with WordPress
--------------------------

[](#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
-----

[](#notes)

- The class uses a protected constant `OBC_CACHE_GROUP` to define a cache group called `evp_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` and `get` methods directly handle data without caching.

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

###  Health Score

22

—

LowBetter than 23% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

873d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8fd19f958b007ec6588d0a5ca2fe78e107edd652f286b836d36b5d1781d573a5?d=identicon)[devuri](/maintainers/devuri)

---

Top Contributors

[![devuri](https://avatars.githubusercontent.com/u/4777400?v=4)](https://github.com/devuri "devuri (17 commits)")

---

Tags

packagistphpphp-librarywordpresscached dataob-cache

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/devuri-ob-cache/health.svg)

```
[![Health](https://phpackages.com/badges/devuri-ob-cache/health.svg)](https://phpackages.com/packages/devuri-ob-cache)
```

###  Alternatives

[rtcamp/nginx-helper

Cleans nginx's fastcgi/proxy cache or redis-cache whenever a post is edited/published. Also provides cloudflare edge cache purging with Cache-Tags.

23817.0k1](/packages/rtcamp-nginx-helper)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
