Skip to content

Add cookie-based cache with expiration - #1529

Merged
sindresorhus merged 7 commits into
refined-github:masterfrom
fregante:cache
Sep 19, 2018
Merged

sindresorhus merged 7 commits into
refined-github:masterfrom
fregante:cache

Conversation

@fregante

@fregante fregante commented Sep 15, 2018 •

Copy link
Copy Markdown
Member

Fixes #624

Cookies are limited to about 170 entries, which makes it a pretty short cache though

@sindresorhus

Copy link
Copy Markdown
Member

I don't really like this. Feels like abuse of cookies. And cookies are sent with every request, so this will actually slow down requests, right? And the hard limit on cookies is pretty low. I think it would be better to just use a LRU implementation with support for TTL for our caching. What are the benefits of cookies? I only see downsides. Maybe native TTL, but TTL is not that to do ourselves.

@fregante

fregante commented Sep 17, 2018 •

Copy link
Copy Markdown
Member Author

And cookies are sent with every request

No because they're stored on background.js's domain, so they're exclusive to RGH and never sent anywhere

What are the benefits of cookies?

13 lines of code to have TTL https://github.com/sindresorhus/refined-github/blob/16eb017f29af3e8358a07f2bf4f091f38ca8f3a3/source/libs/cache.js#L41-L55

TTL is not that to do ourselves

?

The only downside I see is the low limit

@sindresorhus

Copy link
Copy Markdown
Member

TTL is not that to do ourselves

Was trying to say that TTL is not that hard to do ourselves.

Roughly: We just need an entry that contains an object with all the keys and their TTL timestamp as value, and then for every get/set we check the last time the DB was cleaned and if it's time to clean, get the all the keys in the TTL entry, and delete the ones that are expired. We don't need any accurate TTL, so we can implement it the simple way.

@fregante

fregante commented Sep 17, 2018 •

Copy link
Copy Markdown
Member Author

The issue has been open for a year and that solution never materialized however 😃

The “full names” cache is probably pretty long for many users by now

@sindresorhus

Copy link
Copy Markdown
Member

Alright. I guess this is better than what we have now and I don't have time either to do something better than cookies. I still think we should do it eventually though.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants