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

Provide a way to iterate through a cache #22

Closed
whitfin opened this issue Apr 20, 2016 · 0 comments · Fixed by #23
Closed

Provide a way to iterate through a cache #22

whitfin opened this issue Apr 20, 2016 · 0 comments · Fixed by #23
Assignees

Comments

@whitfin
Copy link
Owner

whitfin commented Apr 20, 2016

Although I wouldn't recommend this as a heavily-used operation, it does make sense to have a way to iterate the cache (similar to Redis' SCAN command family).

It'd be neat if there were a function of Cachex.stream(cache, options) which can be used to iterate a cache in such fashion:

:my_cache |> Cachex.stream! |> Enum.to_list

This would allow various filtering and whatnot, in order to allow people to filter out cache values and operate on them appropriately. For example if you wanted to delete all keys beginning with a:

list_of_a =
  :my_cache
  |> Cachex.stream!
  |> Enum.filter(fn{ key, value } ->
        String.starts_with(key, "a")
      end)
  |> Enum.to_list

Cachex.execute(:my_cache, fn(worker) ->
  Enum.each(list_of_a, &(Cachex.del(worker, &1))
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant