mevada-kalpesh/cache-watcher

Cache Watcher 是一个强大的 Laravel 扩展包,通过优化数据管理来提高应用程序性能

dev-main 2024-05-16 16:41 UTC

This package is auto-updated.

Last update: 2024-09-16 17:34:38 UTC


README

Cache Watcher 是一个强大的 Laravel 扩展包,通过优化数据管理来提高应用程序性能。使用 Cache Watcher,您可以在数据变化时无缝管理数据,并享受自动更新。

结果

Alt Text

安装

您可以通过 composer 安装此包,如果命令出错,请将 :dev-main 添加到末尾作为版本号

composer require mevada-kalpesh/cache-watcher

在安装包后,将此提供者在 config/app.phpProviders 中添加

 Kalpesh\CacheWatcher\CacheWatchServiceProvider::class

您可以使用以下命令发布配置文件

php artisan vendor:publish --provider="Kalpesh\CacheWatcher\CacheWatchServiceProvider"

这是已发布配置文件的内容

// config/cache-watcher.php

<?php

return [
    /*
    *   Time will be consider into minutes
    */
    'expire_time' => 1440,


    /*
    *   Cache Store Name  
    */
    'store' => env('CACHE_DRIVER', 'file'),
];

用法

要使用它,您可以按照以下步骤操作

use Kalpesh\CacheWatcher\Facade\CacheWatch;
  // When any values change, the cache is automatically invalidated, and the latest data is fetched using the query.
  $search = "Johsn";
  $pagination = 10;
  $sortBy = "DESC"    

  $posts =  CacheWatch::setQuery(function () use ($search,$pagination,$sortBy){
    // You can use any complex query with Cache Watcher.
      return Post::where('name','like',"%$search%") 
            ->orderby('id',$sortBy)
            ->paginate($pagination);
  })
  //You can set your model as a watcher using `watchModals(YOUR MODALS ARRAY)` function, which means if any changes occur with this model, the cache will be automatically removed and updated with the new data.
  ->watchModals(['Post'])  
  ->done();

请确保正确添加命名空间,如上图所示。

测试

composer test

更新日志

请参阅 CHANGELOG 以获取有关最近更改的更多信息。

贡献

有关详细信息,请参阅 CONTRIBUTING

许可证

MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件