StalkR / httpcache

http RoundTripper providing persistent and volatile cache
https://godoc.org/github.com/StalkR/httpcache
Apache License 2.0
21 stars 4 forks source link

expiration support #1

Closed dvirsky closed 10 years ago

dvirsky commented 10 years ago

First of all, thanks for sharing this lib, it's simple and just works.

The cache, especially the persistent, should support expiration. Defining a global expiration should be easy, but defining expiration per request won't be so trivial I suppose without changing the http client API.

Maybe defining expiration policy per url prefix would be a good compromise.

StalkR commented 10 years ago

Glad you like it! Good idea yes. Policy per URL prefix seems complicated, how about a global expiration setting defined at New*() time? I'll work something out and you'll tell me what you think.

dvirsky commented 10 years ago

I've added some initial support for TTL expiration, you can check out this commit: https://github.com/EverythingMe/httpcache/commit/2ecf46c48d4a79e1c6efa4cd205cc42e659b3160

Also, the lock you put on the cache was global, and essentially meant you're able to process one concurrent request - my case was that a request took few seconds and halted a server, so I just removed it. The proper way would be a lock per key or something like that but I didn't have time to write it.

StalkR commented 10 years ago

Nice work! Good catch on the locking issue. Yes it can be improved, maybe we can move locking outside of the HTTP logic (network is slow) back into the cache Get/Put (reading file/memory is fast).

StalkR commented 10 years ago

Closing this thanks to your pull request https://github.com/StalkR/httpcache/pull/2