Java Web Application: How to implement caching techniques?

前端 未结 6 2039
别那么骄傲
别那么骄傲 2020-12-12 18:16

I am developing a Java web application that bases it behavior through large XML configuration files that are loaded from a web service. As these files are not actually requi

6条回答
  •  暖寄归人
    2020-12-12 18:46

    Your question contains several separate questions together. Let's start slowly. ServletContext is good place where you can store handle to your cache. But you pay by having cache per server instance. It should be no problem. If you want to register cache in wider range consider registering it into JNDI.

    The problem with caching. Basically, you are retrieving xml via webservice. If you are accesing this webservice via HTTP you can install simple HTTP proxy server on your side which handle caching of xml. The next step will be caching of resolved xml in some sort of local object cache. This cache can exists per server without any problem. In this second case the EHCache will do perfect job. In this case the chain of processing will be like this Client - http request -> servlet -> look into local cache - if not cached -> look into http proxy (xml files) -> do proxy job (http to webservice).

    Pros:

    • Local cache per server instance, which contains only objects from requested xmls
    • One http proxy running on same hardware as our webapp.
    • Possibility to scale webapp without adding new http proxies for xml files.

    Cons:

    • Next level of infrastructure
    • +1 point of failure (http proxy)
    • More complicated deployment

    Update: don't forget to always send HTTP HEAD request into proxy to ensure that cache is up to date.

提交回复
热议问题