1. Go to this page and download the library: Download ngmy/cached-object library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace App\Models\Physical;
use Illuminate\Database\Eloquent\Model as Eloquent;
class Movie extends Eloquent {}
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;
}
}
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;
}
}
}
namespace App\Models\Logical;
class MovieObserver
{
public function saved($m)
{
Movie::rebuild($m->id);
}
public function deleted($m)
{
Movie::clear($m->id);
}
}