I just work a lot with caching queries on my website with redis.
I realized I had to change Models or Collections to arrays before I can cache them, so I did.
But well, I reached some point where it’s impossible to do this: With pagination, my query return a LengthAwardPagianator object which I need to build the pagination in the frontend. But I cannot cache this. So it’s kinda a dead end for caching paginated lists.
Then I started searching and found a lot of examples where people cached models or collections and it worked, for example like in this video:
So now I further tested and tested and found an issue: Redis.
$test = Cache::rememberForever('mytest', function () {
return User::get();
// Second test: return User::paginate();
});
This little codesnippet which should simply fetch and store the Rainlab users does work with cache driver “array”, but does not work with Redis. The following error message appears:
Exception: Serialization of 'Closure' is not allowed in ..
I could solve it with the ->toArray()
method, but well… then the pagination and other methods I attached to a model (for ex) dont work.
So: I guess this might be a bug, since I do not expect a certain piece of code to work with the one, but not with the other caching method.
Thanks a lot for any help already. ^^