PHPackages                             oscarricardosan/cache\_object - 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. oscarricardosan/cache\_object

ActiveLibrary[Caching](/categories/caching)

oscarricardosan/cache\_object
=============================

Small package for handling cache in code block and not having to use session and avoid 'array\_has' or the like.

v1.1.5(7y ago)0988MITPHP

Since Aug 16Pushed 7y ago1 watchersCompare

[ Source](https://github.com/oscarricardosan/cache_object)[ Packagist](https://packagist.org/packages/oscarricardosan/cache_object)[ RSS](/packages/oscarricardosan-cache-object/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (7)DependenciesVersions (8)Used By (0)

Agnostic php package.

Small package for handling cache in code block and not having to use session and avoid `array_has` or the like.

```
	$productCache= new CacheObject([0=> 'A']);
	$productCache->set(1, 'B');
	if($productCache->exists(0)){
		return $productCache->get(0);
	}
```

```
use Oscarricardosan\CacheObject\CacheObject;

class Product
{

    /**
     * @var CacheObject
     */
    protected $productCache;

    public function __construct()
    {
        $this->$productCache= new CacheObject([
            'potato'=> ['name'=> 'Potato', 'value'=> 10]
        ]);
    }

    public function addTomatoToProducts($value)
    {
        $productCache->set('tomato', $value);
    }

    public function getTomatoProduct()
    {
        if(!$productCache->exists('tomato')){
            $productCache->set('tomato', ['name'=> 'Tomato default', 'value'=> 7]);
        }
        return $productCache->get('tomato');
    }

}

____________________________________________

$product= new Product();

print_r($product->getTomatoProduct());
//['name'=> 'Tomato default', 'value'=> 7]
$product->addTomatoToProducts(['name'=> 'Real Tomato', 'real_value'=> 1200, 'money', 'COP'])

print_r($product->getTomatoProduct());
//['name'=> 'Real Tomato', 'real_value'=> 1200, 'money', 'COP']
```

Method "getOrSet", receives as parameters the key to obtain and if it does not exist it executes the second parameter which must be a function. It works to avoid having to use an "if ($ productCache-&gt; exists ('tomato'))"

```

    public function getTomatoProduct()
    {
        return $productCache->getOrSet('tomato', function(){
    	    return ['name'=> 'Tomato default', 'value'=> 7];
    	})
    }

```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity68

Established project with proven stability

 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

Every ~105 days

Recently: every ~157 days

Total

7

Last Release

2565d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f1213aa6d5681bcbc79b6148c307a936cf64a1acead102fa12f0032dacc730fd?d=identicon)[oscarricardosan](/maintainers/oscarricardosan)

---

Top Contributors

[![oscarricardosan](https://avatars.githubusercontent.com/u/1308027?v=4)](https://github.com/oscarricardosan "oscarricardosan (8 commits)")

### Embed Badge

![Health badge](/badges/oscarricardosan-cache-object/health.svg)

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

###  Alternatives

[predis/predis

A flexible and feature-complete Redis/Valkey client for PHP.

7.8k305.7M2.4k](/packages/predis-predis)[snc/redis-bundle

A Redis bundle for Symfony

1.0k39.4M67](/packages/snc-redis-bundle)[react/cache

Async, Promise-based cache interface for ReactPHP

444112.4M40](/packages/react-cache)[wp-media/wp-rocket

Performance optimization plugin for WordPress

7431.3M3](/packages/wp-media-wp-rocket)[illuminate/cache

The Illuminate Cache package.

12835.6M1.4k](/packages/illuminate-cache)[colinmollenhour/php-redis-session-abstract

A Redis-based session handler with optimistic locking

6325.6M14](/packages/colinmollenhour-php-redis-session-abstract)

PHPackages © 2026

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