bootup.js icon indicating copy to clipboard operation
bootup.js copied to clipboard

How are files evicted?

Open nuria opened this issue 13 years ago • 10 comments

Since files are likely to change... how are they evicted from the cache?

nuria avatar Nov 05 '12 10:11 nuria

We used aggressive caching techniques with our JS, meaning that once they were downloaded they were always there. To make sure people got changes, we'd either append a number to the filename or query string. In Trade Me Touch, we used ASP.nets minification which automatically creates a unique version hash for us.

So that means, it's up to you to "force" a cache change if you make changes to your JS, as the library makes no HTTP requests at all if it already has the file. BootUp will forget any files that aren't mentioned.

So, if you...

new BootUp(["jquery.js?v=1", "site.js?v=1"]);

BootUp will download and remember jquery.js?v=1 and site.js?v=1 (the cache will have jquery.js?v=1 and site.js?v=1).

If you update your site.js...

new BootUp(["jquery.js?v=1", "site.js?v=2"]);

BootUp will download site.js?v=2, but load jquery.js?v=1 from cache (the cache will have jquery.js?v=1 and site.js?v=2).

Hope this helps.

djmc avatar Nov 05 '12 17:11 djmc

I see, so you are really not evicting files at all. Which means that your storage is growing per every one of your changes. Thanks for the prompt response,

Nuria

nuria avatar Nov 06 '12 10:11 nuria

so you are really not evicting files at all

Huh, that's not what I said.

If there is a filename in the cache, and it is no longer referenced in your array, then it is removed from the cache. It isn't growing for every one of the changes.

In the examples above, I specified two files, jquery.js and site.js.

In the first one, it downloaded jquery.js?v=1 and site.js?v=1. But when the number was incremented to site.js?v=2, it was downloaded, and site.js?v=1 was forgotten because it is no longer referenced.

djmc avatar Nov 06 '12 12:11 djmc

In fact you don't have to worry about the cache growing in size. I havent' read the code but seems like it is up to the browser to manage cache size. am i right on this ? @djmc

ecstasy2 avatar Nov 09 '12 01:11 ecstasy2

No, because BootUp is handling all this by itself, the browser just accepts what it is given (unless the size is bigger than the maximum allowed). This means we need to handle this stuff internally, which it does.

djmc avatar Nov 09 '12 10:11 djmc

So, if I want to clean up all files, I have to use this?

new BootUp(["jquery.js?v=1", "site.js?v=2"]);

tarciozemel avatar Nov 28 '12 21:11 tarciozemel

What do you mean by "clean up all files"?

If you want to remove and redownload everything, use the refresh flag in the options structure.

djmc avatar Nov 29 '12 10:11 djmc

The option is "Set to true to delete the local storage cache and redownload everything". If I want (hypothetically) just "to delete the local storage cache"? It's possible?

Regards!

tarciozemel avatar Nov 29 '12 11:11 tarciozemel

If you want to just delete the cache then,

localStorage.removeItem("cache");

djmc avatar Nov 29 '12 12:11 djmc

OK, thank you very much!

tarciozemel avatar Nov 29 '12 12:11 tarciozemel