RangerMauve / hypercore-fetch

Implementation of Fetch that uses the Hyper SDK for loading p2p content
MIT License
37 stars 13 forks source link

Add ability to delete local copy of file #66

Closed josephmturner closed 2 months ago

josephmturner commented 1 year ago

It should be possible to send a request to hyper-gateway which deletes locally-stored copies of a particular hyperdrive file. Users should be able to perform this kind of deletion on files in hyperdrives which are not writable.

I don't see a command in the hyperdrive API which does this, though...

RangerMauve commented 1 year ago

It might be good to add a custom header or querystring to say "delete only cache and not delete the file" or have DELETE on non-writables be a cache clear by default

RangerMauve commented 1 year ago

Also maybe we could use the 'Cache-Control' header? https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control

Maybe we could have new values for it or reuse them.

RangerMauve commented 1 year ago

Also could consider new HTTP methods (was done before) but that means clients like Godot might have trouble: https://github.com/godotengine/godot/blob/master/core/io/http_client.h#L118

alphapapa commented 1 year ago

Yeah, e.g. a HEAD request with Cache-Control: no-cache, no-store could be used to tell the server, "Don't give me the content of this file, just stop caching it locally."

RangerMauve commented 1 year ago

Aslo related to #67

josephmturner commented 1 year ago

Also, see https://github.com/RangerMauve/hypercore-fetch/tree/e886eb06a8da88d2644df4dc62cdd55fe11b4894#fetchhypernameexampletxt-method-delete-headers-x-clear-cache for the precedent for how hypercore-fetch 8 did this.

josephmturner commented 1 year ago

IIUC, the new drive.clear() command does exactly this: https://github.com/holepunchto/hyperdrive-next/pull/45

josephmturner commented 1 year ago

Yeah, e.g. a HEAD request with Cache-Control: no-cache, no-store could be used to tell the server, "Don't give me the content of this file, just stop caching it locally."

I suggest that we use Cache-Control: no-store.

"Note that no-cache does not mean "don't cache". no-cache allows caches to store a response but requires them to revalidate it before reuse. If the sense of "don't cache" that you want is actually "don't store", then no-store is the directive to use." (from https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#no-cache)

I'm not sure whether it makes more sense to use a HEAD or DELETE request. DELETE seems more semantic, but AFAICT, the Cache-Control header is not normally used with DELETE.

josephmturner commented 1 year ago

@RangerMauve what do you think about using HEAD Cache-Control: no-store? Could we make this work recursively on directories?

josephmturner commented 1 year ago

Since my last comment, I think we settled on DELETE Cache-Control: no-store. Does drive.clear() work recursively on directories?

Regardless, it could be a nice API if DELETE Cache-Control: no-store on the root URL, i.e., hyperdrive://PUBLIC-KEY/ called drive.clearAll(). WDYT?

I think in both cases, it's fine to leave the default options arg as { diff: false }.

RangerMauve commented 1 year ago

DELETE to the root is now a drive.purge, the cache control thing is a TODO for now

josephmturner commented 2 months ago

Added in https://git.sr.ht/~ushin/hypercore-fetch-ushin/commit/6856a5f. Thank you!