fireproofsocks

fireproofsocks

Cache package that sits in front of a slow MFA?

I have a pretty simple need – simple enough that it’s not a big deal to implement it as a GenServer or similar, but it’s a common enough use case that someone else must have come up with something that fits the bill. The basic need is to have a cache sit in front of a slow MFA call, e.g. a database query. So the cache acts as the source-of-truth, and the MFA call gets applied periodically so it stays “reasonably” up-to-date, and I can hit the database once every few minutes instead of once every few milliseconds and all would be well with the world.

I’m imagining a GenServer that could be started up something like:

GenCache.start_link(%{name: :db_query1, module: MyApp, function: :slow_db_query1, args: [], refresh_interval_ms: 300_000})

which would call MyApp.slow_db_query1/0 every 5 minutes and cache the result in the GenServer state. I could access the cached data via something like:

GenCache.get(:db_query1)

or force it to refresh via

GenCache.refresh(:db_query1)

and a few other functions – hopefully this expresses the idea.

Is anyone aware of such a package that could be pointed at arbitrary existing functions? I’m not sure if this simple use case would even justify a stand-alone package, but I thought the community would have some valuable thoughts on it. Thanks in advance!

Most Liked

hauleth

hauleth

Cachex for example will fit the bill.

Where Next?

Popular in Questions Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
chewm
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New

Other popular topics Top

_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New

We're in Beta

About us Mission Statement