Can you manipulate locally cached files?
Nowadays it seems pretty risky to use any of the available solutions for deploying a web-browser-side database.
So maybe one开发者_StackOverflow could use HTTP caching in a custom way?
For example, we have some data cached by our web-browser (e.g. rows of a table in .json format) from the latest session. Taking this local file into account, we exclusively AJAX-request the newest data -as opposed to request everything again-, and a we receive a new file.
Then we could merge both files and somehow force its local caching for future sessions.
Is this even possible at all?
With various cache-control settings on your pages, you can set things that should be cached and things that should not be cached. You cannot, however, control whether something really is cached or not and for how long. That is still up to the browser and can depend upon things out of your control (cache settings, use of the browser since it was originally cached, when the user manually cleared the cache, etc...).
So, for example, you could not use caching to reliably offer offline access to your pages/application because, at any time, a page you really need when offline just might not be there when offline.
But, if you're trying to improve performance by saving server round-trips by using caching effectively, it will usually work (though you can't count on it always working).
If I had an app that would benefit greatly from a browser-side storage mechanism, I'd use HTML5 storage when possible and then decide what the fallback mechanism was when that wasn't available depending upon the application. A couple of the choices would be no offline access in older browsers (just store all the data on the server and get it when needed and let caching help improve performance) or use a plug-in (like Google Gears) to offer local storage (requires user to install plug-in).
精彩评论