You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think use cache_key by serializing arguments to string (may be can be md5 string) is not a good idea because :
Sometimes we passed a big object like Dependency Container to arguments array. It make the code slow as its missed run.
Sometimes I want to cache result that can be returned by 2 difference callable functions
Example
// somewhere.php$posts1 = $cache->getCached(['PostService', 'getActive'], ['category_id' => [1,2]]);
// somewhere_else.php run after somewhere.php$posts2 = $cache->getCached(['CategoryService', 'getAllByCategoryId'], [1, 2]);
// I want $posts2 must be got from cache storage by cacheKey='some_key'
The point of this library is to simplify caching for most of the cases and automatic key generation helps it because:
You don't have to worry about using unique keys across the application code
It makes the code shorter
Tha's why I'll keep it.
But I think replacing $cacheKeySuffix with a $cacheKey which, when it is provided, will be used instead of autogenerated key is a good idea. It is a more general solution and has more use cases.
The only problem here is backward compatibility. Let me think about it. If I don't find any solution I'll have to make a major release.
Btw I don't want this library to encourage your 2nd use case. It adds complexity and may provide more risks than benefits. So, unless you know what you are doing, I do not recommend that.
👍 Your idea and work are great !
I think use
cache_key
by serializing arguments to string (may be can be md5 string) is not a good idea because :Dependency Container
to arguments array. It make the code slow as its missed run.Example
So I think it is better if we have this interface
The text was updated successfully, but these errors were encountered: