luewell / laravel-mongodb-cache

为 Laravel 的 MongoDB 缓存驱动器

dev-master 2020-08-23 12:09 UTC

This package is auto-updated.

Last update: 2024-09-23 21:14:36 UTC


README

为 Laravel 的 MongoDB 缓存驱动器

安装

使用 composer 安装

composer require 1ff/laravel-mongodb-cache

如果您使用的 Laravel 版本低于 5.5,请在 config/app.php 中添加服务提供者

'ForFit\Mongodb\Cache\ServiceProvider::class',

config/cache.php 中添加 MongoDB 缓存存储

'stores' => [
    ...

    'mongodb' => [
        'driver' => 'mongodb',
        'table' => 'cache', // name it as you wish
        'connection' => 'mongodb',
    ],
],

更新您的 .env 文件,并将 CACHE_DRIVER 更改为 mongodb

CACHE_DRIVER=mongodb

优点

  • 此驱动程序使用MongoDB TTL 索引,这意味着当缓存键过期时,它将被自动删除。

  • 这样,集合的大小将保持在您预期的范围内,而不会被不必要的数据错误地填充。

  • 此包自动添加一个迁移,通过运行 MongoDB 命令来创建索引。

  • 此包还注册了两个新的命令

      php artisan mongodb:cache:index
    

      php artisan mongodb:cache:dropindex
    

警告

此缓存驱动程序与其他缓存驱动程序不兼容,因为它以不同的方式编码数据。如果您目前正在使用其他 MongoDB 缓存驱动程序,请确保为此设置一个新的集合。

享受吧!