visualize-admin / electricity-prices-switzerland

Compare Swiss electricity prices. Project ownership: Federal Electricity Commission ElCom
https://strompreis.elcom.admin.ch
BSD 3-Clause "New" or "Revised" License
3 stars 0 forks source link

Introduce caching at various levels #65

Closed ptbrowne closed 1 year ago

ptbrowne commented 1 year ago

Improving performance by adding caches.

I first introduced the LRU caches for query then discovered it was possible to do at Apollo level. I had to upgrade Apollo for the directives to work.

The "resolver cache" works by caching responses based on the SPARQL query. It is fairly manual.

The apollo cache works by specifying how things can be cached directly in the schema, then during resolving phase, Apollo checks the lowest cache denominator and decided if it should send HTTP Cache control headers. It is also necessary to add the response cache plugin for the server to really store a cache of the responses (with only the CacheControl plugin, we would only relying on browser caches).

Downside of application server cache is that it does not work great on Vercel, I guess because it is serverless. Good thing is that on Elcom, we start a Next server, it is not serverless. This approach would need to be modified to include a real cache such as Memcache/Redis if we'd want it to work on Vercel. I think it is not crucial to introduce it right now.

image
vercel[bot] commented 1 year ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
elcom-electricity-price-website ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Feb 10, 2023 at 9:18AM (UTC)
ptbrowne commented 1 year ago

I've added a metrics plugin to have poor man's instrumentation through logging.

image