Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace cacheKeySuffix with cacheKey #1

Open
khanhicetea opened this issue May 20, 2016 · 3 comments
Open

Replace cacheKeySuffix with cacheKey #1

khanhicetea opened this issue May 20, 2016 · 3 comments
Assignees

Comments

@khanhicetea
Copy link

👍 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 :

  • 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' 

So I think it is better if we have this interface

public function getCached($callback, array $args = array(), $expireIn = 0, $cacheKey = null);
@ihor
Copy link
Owner

ihor commented May 21, 2016

The point of this library is to simplify caching for most of the cases and automatic key generation helps it because:

  1. You don't have to worry about using unique keys across the application code
  2. 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.

Thank you for your feedback.

@ihor
Copy link
Owner

ihor commented May 21, 2016

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.

@ihor ihor self-assigned this May 21, 2016
@khanhicetea
Copy link
Author

Yah, you're right ! Second case looks very risky.

Btw, if u want to release a major release for first case, I think I can help u by making a PR 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants