doxroot / laravel-redis-cache
A simple way to cache things in Laravel framework using "tags"
Requires
- php: ^8.2
- ext-redis: *
- laravel/framework: ^10.0|^11.00|^12.00
README
composer require doxroot/laravel-redis-cache
Purpose
This library uses Laravel, but with a different approach to tags. It's mutch to say tags, as it uses the default Laravel cache system to create just a wrapper and nothing more around a powerful cache from the default Laravel core system.
What I don't like about tags in Laravel is the default mechanism. Each key stored in a tag has to be added to another list for later cleanup.
Well, in most applications, a simpler solution might be better.
This application will create a key like: tag:filter:key In Redis, we can simply remove all keys that start with some_path*. And that's it. Nothing more with this library.
I am making this available in the hope that it can help someone.
Some additional info
Just extend AbstractRedisCache for other needs. Very simple. Hard to say a library, because it's just an absolute minimal wrapper arounde Cache facade.
DoxrootDbQueryRedisCache::put(key1, value);
DoxrootDbQueryRedisCache::put(key2, value);
Add 2 keys
DoxrootDbQueryRedisCache::put(key3, value, filterKey: test);
DoxrootDbQueryRedisCache::put(key4, value, filterKey: test);
DoxrootDbQueryRedisCache::put(key5, value, filterKey: test1);
DoxrootDbQueryRedisCache::put(key6, value, filterKey: test1);
Add 4 more keys (total 6)
DoxrootDbQueryRedisCache::flush(); // will remove all 6 keys
DoxrootDbQueryRedisCache::flush(test); will remove only key3 && key4
DoxrootDbQueryRedisCache::flush(test1); will remove only key5 && key6
So, just a minimal wrapper for cache.
Some benchmark results:
Code used for Laravel:
Cache:tags([tag-name])->put(key, value);
Cache::tags([tag-name])->flush();
Code using this library:
DoxrootDbQueryRedisCache::put(key, value);
DoxrootDbQueryRedisCache::flush();
Results
Insert 100K rows using Laravel Time: 36.89 seconds
Insert 100K rows using this lib Time: 19.95 seconds
Insert 1M rows using Laravel Time: 373.27 seconds || 6.23 minutes
Insert 1M rows using this lib Time: 203.28 seconds || 3.38 minutes
Remove all data (1M rows) Laravel Time: 5.64 seconds
Remove all data (1M rows) using this lib Time: 1.63 seconds