Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect HTTP Cache headers #21

Open
evert opened this issue Apr 19, 2017 · 10 comments
Open

Respect HTTP Cache headers #21

evert opened this issue Apr 19, 2017 · 10 comments

Comments

@evert
Copy link
Collaborator

evert commented Apr 19, 2017

At the moment we simply cache everything coming from a server, and only expire this when refresh is called. I'm not 100% certain if this is the right way to go about things.

It's worth researching this a bit better.

@evert evert added this to the 2.0 milestone Apr 19, 2017
@evert evert modified the milestones: 2.0, 1.0, 3.0 Apr 6, 2018
@evert evert modified the milestones: 3.0, 4.0 Mar 18, 2019
@evert evert modified the milestones: 5.0, 6.0 Oct 7, 2019
@evert
Copy link
Collaborator Author

evert commented May 11, 2020

Not making this a 6.0 goal (again). It hasn't really been asked for too much and it's too large.

@evert evert removed this from the 6.0 milestone May 11, 2020
@crabmusket
Copy link

Posting this in case it's helpful down the road: https://github.com/kornelski/http-cache-semantics

@evert
Copy link
Collaborator Author

evert commented Jun 28, 2020

Thanks for the link. Looks like that could do a lot of the heavy lifting that I didn't feel like doing :D

@sazzer
Copy link
Contributor

sazzer commented Nov 30, 2020

Being able to disable any caching that Ketting has built-in, and just fall back on the browser cache, would be a simple way to get correct cache behaviour for relatively little work. (Though obviously that won't work for caching embedded resources or anything clever like that)

@evert
Copy link
Collaborator Author

evert commented Nov 30, 2020

Yeah, it has a bunch of issues... off the top of my head:

  1. No way to programmatically expire
  2. No support for Link: <..>; rel="invalidates" which is really just a variant of 1.
  3. No way to store things in the cache for embedded items, PUT
  4. No support for Prefer: return=representation
  5. Can't trigger event handlers like the 'stale' and 'update' events.

So that approach works, but only really if you're using a simpler subset of ketting's features.

@sazzer
Copy link
Contributor

sazzer commented Nov 30, 2020

Fair enough - I didn't realise quite how much of Ketting depended on the caching stuff!

@evert
Copy link
Collaborator Author

evert commented Nov 30, 2020

Yeah, cache has become increasingly important =) Especially since Ketting 6. When this ticket was made it was pretty early days for this lib.

@evert
Copy link
Collaborator Author

evert commented Nov 30, 2020

So yea, I don't have a great idea yet for how to do this proper =)

I want better ways for a server to tell Ketting to do things like 'never cache', and the obvious header is Cache: no-store, which is basically the default for most APIs, but the issue is with the opposite of this..what if we want the server to store an object for an hour? That works with the usual headers, but then Ketting has a few different ways (like mentioned above) where it knows it needs to expire that cache early, or it actually knows the new representation..

So all of this is tricky to handle.

For now I think I'm just going to stick with the Ketting cache as-is, and use the browser cache as an additional cache layer for cases where we know for sure we won't need a new fetch until later.

And maybe come up with a ketting-specific cache header that's ignored by a browser but uses similar semantics. Server-controlled caching is so powerful! The HATEOAS design basically means we want to put as many decisions as possible on the server, and have the client make very few decisions about this kind of stuff.

@sazzer
Copy link
Contributor

sazzer commented Nov 30, 2020 via email

@evert
Copy link
Collaborator Author

evert commented Nov 30, 2020

You are absolutely right @sazzer , it's a solution that only works if you can control server & client. Of course there's nothing stopping people from using these headers for other servers & clients.

In cases where you can't do anything server-side, you're always going to have to add more logic to the client-side. But, if the server does have these bonus headers they shouldn't affect semantics of clients that don't understand them, but clients that do can potentially do smarter things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants