Get execution context OR server-side conditional refresh #317
Replies: 1 comment 3 replies
-
Hi @juantxorena , sorry for the delay, I'm recently onto something quite massive and delicate.
This is interesting! Meanwhile, have you been able to come up with something?
Yes, because the execution context exists only when the factory is being executed, therefore it's not accessible from outside the factory itself.
Eh, this is not possible since for both L1 (
I should think about it more probably, but maybe using 2 cache entries per-content? NB: watch out though for a potential DDoS venue. What I mean is that if every time you receive a request with an ETag different than the one in the cache you go to the database (or whatever it isin your case), somebody can just make a loop requesting random ETags and your database will burn down.
We are all newbie about something 🙂 Hope this helps, let me know! |
Beta Was this translation helpful? Give feedback.
-
I'm trying to implement server-side conditional refresh. The docs only talk about client-side, i.e. a client requesting a remote server.
In my case, I'm implementing the server, which offers an API and does some database queries, some of which are expensive and the data they retrieve changes rarely. So my idea is to cache the database results (and invalidate them when needed), calculate an etag (or last modified or something), and store it in the cache as per the docs. When a client requests something, I would check if the cache has the same tag, and if it does, then return a 304, by implementing a custom policy for output cache as explained in the asp.net docs.
However it doesn't seem possible to do it, since I cannot access the execution context from outside of the delegate, so if I call a GetOrSet, I would only get the value itself, without knowing if it was from the cache or not. Related to this last point, there's this discussion, which might be useful, but it's not ideal, since I'm retrieving a potentially large object (maybe from redis) for nothing.
Another solution could be to get the object and calculate the etag or something everytime, but of course, this is also far from ideal.
What I think it makes more sense for this case, and probably for many other situations, is to be able to retrieve the "metadata" of a cache key without retrieving it, to check things like Etag, LastModified, StaleValue, Duration, and things of the sort, so it could be used for this kind of things.
Is there any better way of doing what I want to do? Does it make sense at all (I'm a newbie in cache stuff)? Would it make sense to implement the GetMetadata function that I'm suggesting?
Beta Was this translation helpful? Give feedback.
All reactions