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)0995MITPHP

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 3w 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 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

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

2614d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1308027?v=4)[Oscar Sanchez](/maintainers/oscarricardosan)[@oscarricardosan](https://github.com/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)
```

PHPackages © 2026

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