LoginSignup
2
1

More than 5 years have passed since last update.

Laravel の illuminate/cache を単体で使用するときの設定

Last updated at Posted at 2018-08-30

laravel のキャッシュ機構を、単体でも使いたい、というときの方法。

とりあえず今回はファイルキャッシュのみで。

パッケージをインストール

illuminate/cache と、ファイル操作用に illuminate/filesystem を入れる

composer require illuminate/cache illuminate/filesystem

初期化

Filesystem と FileStoreを作って、そこからキャッシュリポジトリを作成。

$filestore = new \Illuminate\Cache\FileStore(new \Illuminate\Filesystem\Filesystem(), $cache_dir);
$cache = new \Illuminate\Cache\Repository($filestore);

これで使える

$cache->put('key', $value, $minutes);
$value = $cache->get('key');

以上です

バージョン5.6 で確認しました

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1