-
Notifications
You must be signed in to change notification settings - Fork 96
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
Post purge hooks? #17
Comments
@lostboy you should realistically be able to receive a Edit: ha, I knew that this was broken previously but for different reasons... I fixed it but only ever tested it with the internal Stats hook so I totally missed that it wouldn't fire the rest of the hooks. Fix incoming! |
Ok, this is now resolved in the main branch so you can pick it up from here. The next version will be released on Hex pretty soon, just gotta review a few things. For what it's worth, I always intend master to be stable enough to use (otherwise I keep changes in PR until it is stable), so it should be ok to just point your projects to the GitHub. For reference, here's the test case I used to make sure the hooks were receiving: Erlang/OTP 18 [erts-7.3] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
Interactive Elixir (1.2.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> defmodule MyModule.PostPurgeHook do
...(1)> use Cachex.Hook
...(1)>
...(1)> def handle_notify({ :purge, _opts }, state) do
...(1)> IO.puts("Purge received!")
...(1)> { :ok, state }
...(1)> end
...(1)>
...(1)> def handle_notify(_action, state) do
...(1)> { :ok, state }
...(1)> end
...(1)> end
{:module, MyModule.PostPurgeHook,
<<70, 79, 82, 49, 0, 0, 13, 96, 66, 69, 65, 77, 69, 120, 68, 99, 0, 0, 2, 221, 131, 104, 2, 100, 0, 14, 101, 108, 105, 120, 105, 114, 95, 100, 111, 99, 115, 95, 118, 49, 108, 0, 0, 0, 4, 104, 2, ...>>,
{:handle_notify, 2}}
iex(2)> Cachex.start_link([ name: :my_cache, hooks: %Cachex.Hook { module: MyModule.PostPurgeHook, type: :post }, default_ttl: :timer.seconds(3), ttl_interval: :timer.seconds(5) ])
{:ok, #PID<0.149.0>}
iex(3)> Cachex.set(:my_cache, "key", "value")
{:ok, true}
Purge received!
iex(4)> If you want to know how many were purged, you need to add I hope this solves your issue, and thank you very much for the kind words 😃 Please let me know if you come across anything else, or have further questions about this! |
Is there a way to be notified when entries are purged? Really great project btw, using it more and more.
The text was updated successfully, but these errors were encountered: