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

cache_put does not work when passing a list of keys #127

Closed
cschmatzler opened this issue Jul 15, 2021 · 8 comments
Closed

cache_put does not work when passing a list of keys #127

cschmatzler opened this issue Jul 15, 2021 · 8 comments

Comments

@cschmatzler
Copy link

Hi!

Checking out the library right now and trying to follow the examples.
Right in the README, this is shown:

 @decorate cache_put(
              cache: Cache,
              keys: [{User, usr.id}, {User, usr.username}],
              match: &match_update/1
            )
  def update_user(%User{} = usr, attrs) do
    usr
    |> User.changeset(attrs)
    |> Repo.update()
  end

I cannot get this working. Running an update method on a record with cache_put(cache, key: {User, usr.id}, match: &match_update/1) works just fine and updates the one key in the cache with the updated record.
Passing multiple keys as a list does add one to Cache.count_all, no matter how many keys are in the list, and does not update the {User, usr.id} key at all.

Not sure how to provide a minimal reproduction because I essentially copy and pasted the README.

Cheers

@cschmatzler
Copy link
Author

Added a test for this in https://github.com/cschmatzler/nebulex/commit/9c93e4b2d4b079d79716f3dd99cbd46dd4042636 which expectedly fails.

@cabol
Copy link
Owner

cabol commented Jul 16, 2021

Hey 👋 !

You are facing that issue with the cache_put because the :keys option is only available for cache_evict currently (you can check the docs, and the option is only for cache_evict).

However, it could be possible to extend the :keys option to the rest of the caching annotations, but that would be an additional improvement (I will check and open a separate issue for it).

Thanks.

@cschmatzler
Copy link
Author

Hi!
Thank you for your quick reply.

In that case, the quick start example in the README is incorrect:

keys: [{User, usr.id}, {User, usr.username}],

I'll see if I can help you out and at least get the README updated over the weekend.
Other than that, being able to put multiple keys on update like in that example would be a great enhancement.

Have a great day!

@cabol
Copy link
Owner

cabol commented Jul 16, 2021

Yeah, you're absolutely right, that is a mistake in the README, I will fix it, and yes, totally agree, I think that would be a good improvement, will try to work on it this weekend!

@cabol
Copy link
Owner

cabol commented Jul 16, 2021

Created Issue #128

@cabol
Copy link
Owner

cabol commented Jul 18, 2021

Hey! I pushed to the master branch some changes adding support for :keys option in the cache_put annotation. Please check it out and let me know if you face any issues. Stay tuned!

@cschmatzler
Copy link
Author

Hey Carlos! master branch looks great and the code I had in mind works well now.
Really appreciate your super quick response and the nice enhancement.

Thanks for the great library and I hope you have a wonderful week!

@cabol
Copy link
Owner

cabol commented Jul 19, 2021

Thanks 🙇‍♂️ !! Will publish a new release with this enhancement very soon!!

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

No branches or pull requests

2 participants