Hello,
I am in a situation where I manage per-user data in a “cache” genserver (but it’s not just a cache, it also does some computation on the data). On the other side, the front-end SPA interacts through channels.
I would like to free the cache when users are idle/away. The Presence behaviour is great but a bit too much responsive in this case. For instance: I don’t want the cache to be thrown away when a user reloads the page (thus triggering successive presence_diff events).
My idea is anyway to rely on Presence.track: on each “leave” event, launch a countdown with :timer.sleep/1
in a separate process. If the user joins again in the meantime, clear the countdown (referenced in another registry-like genserver), but do empty the cache if the countdown expires.
Do you see any drawback to this approach? Thanks!