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 2mo 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

4423d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7420a4f9654469ce1854f94fe56c240f0b930e692cdcfc8746f8a46480d9579d?d=identicon)[ngmy](/maintainers/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.8k8.2M51](/packages/spatie-laravel-responsecache)[awssat/laravel-visits

Laravel Redis visits counter for Eloquent models

975163.6k2](/packages/awssat-laravel-visits)[barryvdh/laravel-httpcache

HttpCache for Laravel

513400.6k7](/packages/barryvdh-laravel-httpcache)[dragon-code/laravel-cache

An improved interface for working with cache

6844.8k9](/packages/dragon-code-laravel-cache)[anahkiasen/flatten

A package for the Illuminate framework that flattens pages to plain HTML

33313.0k](/packages/anahkiasen-flatten)[nexxai/laravel-cfcache

A handful of Cloudflare cache helpers for Laravel

1317.7k](/packages/nexxai-laravel-cfcache)

PHPackages © 2026

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