PHPackages                             ngmy/cached-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. ngmy/cached-object

ActiveLibrary[Caching](/categories/caching)

ngmy/cached-object
==================

A caching scheme for an object for Laravel 4, inspired by Enterprise Rails

0.1.0(12y ago)116[1 issues](https://github.com/ngmy/cached-object/issues)MITPHPPHP &gt;=5.3.0

Since Mar 30Pushed 12y agoCompare

[ Source](https://github.com/ngmy/cached-object)[ Packagist](https://packagist.org/packages/ngmy/cached-object)[ Docs](https://github.com/ngmy/cached-object)[ RSS](/packages/ngmy-cached-object/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (3)Versions (2)Used By (0)

Cached Object
=============

[](#cached-object)

[![Build Status](https://camo.githubusercontent.com/626a1dabb686e8f6449021602d51ec0de78c9cf52e62fa3f5b3c582cad06731a/68747470733a2f2f7472617669732d63692e6f72672f6e676d792f6361636865642d6f626a6563742e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/ngmy/cached-object)[![Coverage Status](https://camo.githubusercontent.com/bf692a419fbc57064f73ab65e54bc31660978ea1837277dd6580f90d7a13abaf/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6e676d792f6361636865642d6f626a6563742f62616467652e706e673f6272616e63683d6d6173746572)](https://coveralls.io/r/ngmy/cached-object?branch=master)

A caching scheme for an object for Laravel 4, inspired by [Enterprise Rails](http://enterpriserails.chak.org/).

Requirements
------------

[](#requirements)

The Cached Object has the following requirements:

- PHP 5.3+
- Laravel 4.0+

Installation
------------

[](#installation)

Add the package to your `composer.json` and run `composer update`:

```
{
    "require": {
        "ngmy/cached-object": "dev-master"
    }
}
```

Add the following to the list of service providers in `app/config/app.php`:

```
'Ngmy\CachedObject\CachedObjectServiceProvider',
```

Add the following to the list of class aliases in `app/config/app.php`:

```
'CachedObject' => 'Ngmy\CachedObject\CachedObject',
```

Examples
--------

[](#examples)

### Basic Usage

[](#basic-usage)

1. Create a physical model, which inherits from Eloquent:

```
namespace App\Models\Physical;

use Illuminate\Database\Eloquent\Model as Eloquent;

class Movie extends Eloquent {}
```

2. Create a logical model, which inherits from CachedObject:

```
namespace App\Models\Logical;

use CachedObject;

class Movie extends CachedObject {

    public static $VERSION = 1;

    public $id;

    public $name;

    public $lengthMinutes;

    public function __construct($id, $name, $lengthMinutes)
    {
        $this->id            = $id;
        $this->name          = $name;
        $this->lengthMinutes = $lengthMinutes;
    }

}
```

You need to define `$VERSION`. This property is used to create a unique cache key for a requested object. Please increments this number when you change a structure of a class.

3. Create a logical model of an uncached version, which a class name starts with **Uncached**:

```
namespace App\Models\Logical;

class UncachedMovie {

    public static function get($id)
    {
        $m = \App\Models\Physical\Movie::find($id);

        if (is_null($m)) {
            return null;
        } else {
            $movie = new Movie(
                $m->id,
                $m->name,
                $m->length_minutes
            );
            return $movie;
        }
    }

}
```

In order to get an object of a logical model, you need to define a method whose name starts with **get**. This method is called only if an object does not exist in a cache.

4. Now, you can get an object from a cache by calling `Movie::get()`.

### Physical Model Observers

[](#physical-model-observers)

1. Create a observer.

For example, to rebuild a cache when you updated a physical model, and also to delete a cache when you deleted a physical model, define a observer as follows:

```
namespace App\Models\Logical;

class MovieObserver
{
    public function saved($m)
    {
        Movie::rebuild($m->id);
    }

    public function deleted($m)
    {
        Movie::clear($m->id);
    }
}
```

2. Register a observer to a physical model:

```
\App\Models\Physical\Movie::observe(new \App\Models\Logical\MovieObserver);
```

### More Usage

[](#more-usage)

Please see my unit tests.

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 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

4476d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/864041?v=4)[Yuta Nagamiya](/maintainers/ngmy)[@ngmy](https://github.com/ngmy)

---

Top Contributors

[![ngmy](https://avatars.githubusercontent.com/u/864041?v=4)](https://github.com/ngmy "ngmy (1 commits)")

---

Tags

cacheLaravel 4

### Embed Badge

![Health badge](/badges/ngmy-cached-object/health.svg)

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

###  Alternatives

[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k9.0M66](/packages/spatie-laravel-responsecache)[illuminate/cache

The Illuminate Cache package.

12937.0M1.7k](/packages/illuminate-cache)[awssat/laravel-visits

Laravel Redis visits counter for Eloquent models

978172.3k2](/packages/awssat-laravel-visits)[iazaran/smart-cache

Smart Cache is a caching optimization package designed to enhance the way your Laravel application handles data caching. It intelligently manages large data sets by compressing, chunking, or applying other optimization strategies to keep your application performant and efficient.

21111.6k](/packages/iazaran-smart-cache)[nexxai/laravel-cfcache

A handful of Cloudflare cache helpers for Laravel

13014.7k](/packages/nexxai-laravel-cfcache)[dragon-code/laravel-cache

An improved interface for working with cache

7046.0k10](/packages/dragon-code-laravel-cache)

PHPackages © 2026

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