d

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore.

15 St Margarets, NY 10033
(+381) 11 123 4567
ouroffice@aware.com

 

KMF

ORM Caching Package for Laravel

LaraCache is an ORM-based package for Laravel to create, update and manage cache items based on model queries. Using this package, you can cache queries that you use heavily throughout your application.

1use MostafaznvLaraCacheTraitsLaraCache;

2 

3class Article extends Model

4{

5 use LaraCache;

6 

7 public static function cacheEntities(): array

8 {

9 return [

10 CacheEntity::make('list.forever')

11 ->cache(function() {

12 return Article::query()->latest()->get();

13 }),

14 

15 CacheEntity::make('latest')

16 ->validForRestOfDay()

17 ->cache(function() {

18 return Article::query()->latest()->first();

19 })

20 ];

21 }

22}

Using the cacheEntities method to define cached queries, Laracache will take care of the rest. To use the cached queries, you’ll call the model like the following example:

1use MostafaznvLaraCacheFacadesLaraCache;

2 

3 

4$cache = Article::cache()->get('latest');

5// or

6$cache = LaraCache::retrieve(Article::class, 'latest');

With this package, you can control cache with the following features:

  • Enable/disable cache
  • Update cache manually
  • Update all cache entities manually
  • delete cache
  • Control CacheEntity duration using fluent methods or a ttl() method

I thought the following manual cache update method was neat, refreshing your cache on-the-fly:

1Article::cache()->update('latest');

2// or

3LaraCache::update(Article::class, 'latest');

You can learn about this package, get full installation instructions, and view the source code on GitHub.

Credit: Source link

Previous Next
Close
Test Caption
Test Description goes like this