6 ms·
What is being cached? I don't understand what there is to cache in a web framework. Is it to cache rendered pages without dynamic content? If so, I think it
by JonathanBeuys 5y ago
What is being cached?
I don't understand what there is to cache in a web framework.
Is it to cache rendered pages without dynamic content?
If so, I think it is better to let a CDN handle that. Instead of the server that runs the web application.
What am I missing?
- TylerE 5y agoGenerally the approach is fragment caching... so you're caching some block of HTML that would otherwise hit the DB (Think something like a block of configurable sidebar links, or a "latest posts" block. HTML, not assets. Some such setups (like one I wrote for a busy Drupal newspaper site way back when) can support clearing relevant cache entries on DB write, so you're essentially never serving stale data, but can save _substantial_ DB load - and possibly webserver load too, depending on how computationally intensive the HTML generation is.
- jayd16 5y agoI guess this is easier than read replicas? I can't imagine there's too much work to be saved by skipping the component building.
- TylerE 5y agoYes, if the queries involve lots of fiddly calculation (for instance, the newspaper system did a lot of fancy stuff around calculating good line breaks and wrapping, or the queries themselves are complicated, involve subqueries, many joins, etc.
- zepolen 5y agoDB lookup + rendering vs cache lookup + concatenating. Yes it adds up.
- BiteCode_dev 5y agoFirst, there are people that don't want to use a CDN (don't trust them with censorship), or can't (local network). But you can cache other things that are not the entire page itself: - database queries - user sessions - api calls - page fragment - function memoization What's more, cache backends have the ability to expire things, which can be helpful for all sort of stuff.
- asmosoinio 5y agoThe data being cached does not need to be related to the web framework as much as the application logic. E.g. results from external services, calculations, anything that an application might want to cache. Am working on a somewhat large Django system, and there is a ton of different things we cache in Redis. Also HTML template results as another comment mentioned, but mostly something else entirely, related to the application logic.
- MattGaiser 5y agoDatabase queries are a big one in some cases.
- matsemann 5y agoAnything. What's annoying with Python though is how hard it is to just cache stuff in some dict or other data structure, since the GIL basically forces each request to have it's separate process (instead of separate thread). So non-trivial to share some state application wide without having to store it outside the application. Of course a shared cache is sensible when there are multiple nodes running the application. But not everything needs a global cache either, or maybe the point of the cache was exactly to avoid a round trip to something else.