First of all, my website currently uses these components
"require": { "symfony/http-foundation": "^3.1", "symfony/routing": "^3.1", "symfony/http-kernel": "^3.1", "symfony/event-dispatcher": "^3.1", "pimple/pimple": "~3.0", "illuminate/database": "^5.3" },
Because I use symfony's event-dispatcher component instead of laravel's events component,
so this comes with the setting event when the Eloquent ORM service is initialized The monitoring function does not work
use Illuminate\Events\Dispatcher; use Illuminate\Container\Container; $capsule->setEventDispatcher(new Dispatcher(new Container));
and I don’t want to use two components with duplicate functions, so I cannot monitor the Eloquent ORM events and cache them.
What I want to achieve is mainly to use memcache to cache the data of Eloquent ORM query events. How to do this step...
First of all, my website currently uses these components
"require": { "symfony/http-foundation": "^3.1", "symfony/routing": "^3.1", "symfony/http-kernel": "^3.1", "symfony/event-dispatcher": "^3.1", "pimple/pimple": "~3.0", "illuminate/database": "^5.3" },
Because I use Symfony's event-dispatcher component does not use Laravel's events component. So when the Eloquent ORM service is initialized, the built-in event monitoring function cannot be used.
use Illuminate\Events\Dispatcher; use Illuminate\Container\Container; $capsule->setEventDispatcher(new Dispatcher(new Container));
What I want to achieve is to use memcache to cache the data of Eloquent ORM query events. How to do this step...
remember method to cache query data.
$value = Cache::remember('users', $minutes, function() { return DB::table('users')->get(); });
protected static function boot() { parent::boot(); static::created(function ($model) { // cache model }); }
saving
saved
updating
updated
creating
created
deleting
deleted
The above is how Eloquent ORM listens to its events and then uses memcache to cache the data. For more related content, please pay attention to the PHP Chinese website (www.php .cn)!