swayok / alternative-laravel-cache

Replacements for Laravel's redis and file cache stores that properly implement tagging idea
MIT License
169 stars 26 forks source link

unserialize() Error at offset 147440 of 147456 bytes #29

Closed pravo-pro closed 3 years ago

pravo-pro commented 3 years ago

Hi! When cache was small all work fine. now cache contains 100k files and tag files become big. when i try clear cache by tag or remove cache by name and it exist in tag file i get errors [2021-05-26 08:23:40] prod.ERROR: unserialize(): Error at offset 147440 of 147456 bytes {"exception":"[object] (ErrorException(code: 0): unserialize(): Error at offset 147440 of 147456 bytes at /vendor/cache/filesystem-adapter/FilesystemCachePool.php:162) [stacktrace]

our base contain 1kk elements each has own detail page - 1kk cached items with different tags will be..

swayok commented 3 years ago

Hi. I have no direct connection to developers of cache/filesystem-adapter library. You can report this issue here: https://github.com/php-cache/issues/issues. Your problem probably happened because of simultaneous read-write access to tags registry file. This is the biggest downside of using file-based cache. In your case I'd better switch to some 'in-memory' cache driver like redis because file-based cache has very high impact on your HDD when you have high amount of requests (not so much if you use SSD, but it still will have some problems). It actually may significantly slow down your project instead of speeding it up. As alternative - you can use several different configs to store your cache files in different folders and lower the amount of files per folder/tags registry file. Also try not to read cached data in a loops - this will make your script very slow even with in-memory cache.

pravo-pro commented 3 years ago

It would be great if the customer had a good hosting service with a large amount of memory. But the current server has only 1GB of RAM. Therefore, the option of storing the cache in memory has not yet been considered. But I understood the reason. I will discuss the options with the customer.