siddhant3030
How do I build a caching service in elixir?
Suppose I have two tables in my database. I want to build a service in elixir which should pick data from my database and cache each rows in redis keys.
- I want to use genserver and supervisor to do this.
Can anyone tell me how do I go about it?
Most Liked
wanton7
Do you really need to use Redis? If it is not mandatory to use it, then maybe just use GitHub - whitfin/cachex: A powerful caching library for Elixir with support for transactions, fallbacks and expirations · GitHub Instead.
lucaong
Hi @siddhant3030,
I think that more information about your case would make it easier for people to help you with this:
-
Why is
SupervisorandGenServera requirement? Is this an exercise/coding challenge, or you have specific needs with regards to resilience? If it’s about resilience, in order to design the supervision it’s useful to know how you want the system to react to failures (wipe all cached values, keep the cached values, restart the whole system or only specific parts, etc.) -
What is the expected behavior of the caching service? When should values be purged from the cache? What is the cache key? How are values retrieved from the database?
-
Is Redis a requirement, or just an idea?
If you just want some starting point, you can have a look at the official Elixir getting started guide, that has a very similar example. The guide walks you through the implementation of a key/value store using various techniques, from Agent to GenServer, Supervisor, ETS, etc. Caching services are usually key/value stores with some logic on top, so that might put you on the right track.
andreaseriksson
Sounds like it. ![]()
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








