PHPSocialNetwork / phpfastcache

A high-performance backend cache system. It is intended for use in speeding up dynamic web applications by alleviating database load. Well implemented, it can drops the database load to almost nothing, yielding faster page load times for users, better resource utilization. It is simple yet powerful.
https://www.phpfastcache.com
MIT License
2.36k stars 452 forks source link

Deleting cache by tag without loading all its cache #900

Closed mlavrinenko closed 1 year ago

mlavrinenko commented 1 year ago

What's your question ?

Hello!

TaggableCacheItemPoolTrait->deleteItemsByTags loads all tag items and then deletes them. It can lead to high memory usage.

I cache a lot of fragile data. Any change in one piece of data should delete all tagged cache entirely. I considered the clear method, but I have some exceptions when some chunks of data isn't fragile and should survive such a cleanup.

CacheDeleteItem event can still be dispatched, but with lazy loading object passed to it. That means if there is no event handlers then no data will be loaded from driver.

Or I just miss something?

References (optional)

https://github.com/PHPSocialNetwork/phpfastcache/blob/8614c5624e56b6f41fa666fdec3dc746b52df6b4/lib/Phpfastcache/Core/Pool/TaggableCacheItemPoolTrait.php#L142

Do you have anything more you want to share? (optional)

No response

github-actions[bot] commented 1 year ago

Hello curious contributor ! Since it seems to be your first contribution, make sure that you've been:

Geolim4 commented 1 year ago

Hello,

Sorry for late reply. The choice of loading cache item tags into the memory was because not all backends (like Redis) do support cache tags operations.

That means you need to handle them on the phpfastcache-level for others backends.

I wisely made the choice years ago because it was easier to implements and completely transparent for the developer.

I advice you to split your "crucial data" to a new different cache instance of phpfastcache that will survive even if your clear the data of your other cache instance.

Cheers, Georges

Geolim4 commented 1 year ago

Hello @mlavrinenko,

I’m closing this issue for now because of (inactivity / outdated code / …).

You can always reopen it though! :) Please (update the issue / add comment / clarify …).

Regards, Georges.L