kanishka

kanishka

Anybody implemented http caching when serving a rest API or graphql?

I am curious if there are any plugs or libraries that help implement http cache headers (REST API Response Caching - When and Where?) for a rest API or graphql server?

Most Liked

dimitarvp

dimitarvp

I only ever heard good things about Varnish, Squid, nginx, Caddy and several others.

But IMO the main challenge is having the right caching key; this is why in-app caching is so powerful because you can cache an object through its ID and have any updating logic update the cached object, and any readers will be none the wiser because they’ll fetch it from cache 99% of the time (the other 1% being the object expiring due to TTL policy, or a race condition).

It’s trivially easy to setup many web servers to cache pretty much anything but then it falls on you to always return the right modified / etag response headers. Which is also pretty easy.

All in all, it is a “pick your poison” type of stuff really.

BartOtten

BartOtten

Plus:

  • you can test it without running an extra service
  • you can use libs to form BEAM clusters, sharing cache (or broadcast cache updates)
  • one less single point of failure

But before you go the extra cache route: make sure you need it!

  • most databases already have build-in (very powerful) caching. Their default settings are always on the safe side memory wise and mot always adjusted to the amount of cheap memory available in machines today. As a result they cache a lot less than your machine can handle. So before anything else: learn how to tweak the database settings.
  • even simple caching layers add code and complexity.
  • have seen many projects with fancy (but complex) caching layers only to have 100 requests…per hour.

Where Next?

Popular in Discussions Top

mikl
I wanted to capitalize a string, and tried using String.capitalize(). That generally works well, until you try to capitalize a word like...
New
Rustixir
Hi everyone, im working on find best language/framework/system for high concurrency, high performance and stable performance after wor...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
mmport80
I have put far too much effort into Dialyzer over the last year or so - and basically - I doubt it’s worth the effort. It’s not as easy ...
New
crabonature
I’m still quite new to Elixir. As I understand we got in Elixir “multi guards” as convention to simplify one large guard with or’s?: de...
New
AlexMcConnell
The reason that Rails is as popular as it is is because it’s very easy for relatively inexperienced developers to get a lot of work done....
588 19652 166
New
AstonJ
Can you believe the first professionally published Elixir book was published just 8 years ago? Since then I think we’ve seen more books f...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
Fl4m3Ph03n1x
Background A few days ago I was listening to The future of Elixir from Elixir Talks, with Dave Thomas (@pragdave ) and Brian Mitchell. I...
New
fireproofsocks
This is more of a general question, but I’m wondering how other people in the community think about the pattern matching in function sign...
New

Other popular topics Top

danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29603 241
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39467 209
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
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement