开发者

Design of caching for a medium/small web app? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 4 years ago.

Improve this question

I have a web app that's currently ~700 LOC in JS (more is serverside). I'm using jQuery. As I find myself trying to minimize AJAX requests to the server, I've got an awkward mix of caching and spaghetti code developing. It feels like I need a more centralized solution.

My idea: Create a map with the AJAX call to make (URL and args), and a di开发者_JS百科rty bit. If part of the app decides that the data in the map is outdated, it sets the dirty bit to true. If a part of the app requests the data, and the data is dirty or doesn't exist, the map will request it from the server before returning it. Otherwise, the map will return it directly.

Does that sound like a good design? Or is there a jQuery plugin or some other code that already does this?


Sounds good to me. You're basically creating a custom caching system. You have a way to invalidate and refresh your cache on demand. That's all any caching system has at the core.

As far as available libraries for jQuery, I couldn't say.


jCache plugin is a jQuery plugin that allows you to cache by key (URL and args in your case). When you retrieve the value you could make an object to contain your real data and the dirty flag (or a Date object as an expiration control).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜