Does ehcache uses same cache for all clients

流过昼夜 提交于 2019-12-11 04:28:31

问题


I am trying to use ehcache cache. For two different user my webservice creates different cache which is acting like session. Can i create single cache which will work same as context concept


回答1:


Please look at Ehcache Cache server

http://ehcache.org/documentation/user-guide/cache-server

For sample Java code, see this link: http://ehcache.org/documentation/user-guide/cache-server#java-code-samples

Hope it helps




回答2:


When instantiating an EhCache CacheManager (which is the first step in getting a reference to a Cache object) you have several options per EhCache APIs:

  1. "Traditionnal" object contructor: new CacheManager(). As explained in the API page, "This method does not act as a singleton. Callers must maintain their own reference to it."
  2. Static constructor: CacheManager.create(). This creation method does act as a singleton, which means that you can call the CacheManager.create() for every requests or sessions...and it will always return the same CacheManager.

Since you haven't provided any detail on your implementation, I can only suppose that you are (knowingly or not) creating a new CacheManager object (http://ehcache.org/apidocs/net/sf/ehcache/CacheManager.html) per service request or session...and that would explain the behavior you're noticing.

If you were using the singleton concept for creating the CacheManager (method 2), you would indeed create a single CacheManager + get a single reference to a Cache object that can be access accross threads (requests, sessions, etc ...)



来源:https://stackoverflow.com/questions/17652178/does-ehcache-uses-same-cache-for-all-clients

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!