0

We're using the LightweightBrowserCache provided by RESTEasy 2.2.3.GA but have noticed that when the cache size limit is reached, the cache is cleared completely. Obviously this severely reduces the chance of cache hits, because there's no way that the most regularly used items can remain in the cache.

We'd like to create a more sophisticated implementation (e.g. based on Ehcache) that would evict the least recently used items when the size limit is reached.

Does anyone know of a good, open source implementation of org.jboss.resteasy.client.cache.BrowserCache that we could use?

or

Have you implemented your own org.jboss.resteasy.client.cache.BrowserCache and if so do you know of any gotchas we should be careful to avoid?

joelittlejohn
  • 11,665
  • 2
  • 41
  • 54

2 Answers2

2

We have used Apache HTTP Client with its Caching component together with RestEasy Client Framework to get around this limitation of LightweightBrowserCache. RestEasy allows integrating with Apache HTTP Client Component, details can be found in RestEasy documentation.

s.tikoo
  • 86
  • 7
  • This works nicely. Shame you can't set a total size limit in bytes for the BasicHttpCacheStorage (you can only set a number of entries limit and max size per entry). A much better solution than the RESTEasy lightweight browser cache tho. Thanks! – joelittlejohn May 24 '12 at 15:15
1

You can try with Resteasy default caching technique.

Cache response only for GET request when response is 200 OK,

Test environment : Jboss6.4 and maven 3.0

Dependency :

<dependency>
  <groupId>org.jboss.resteasy</groupId>
  <artifactId>resteasy-cache-core</artifactId>
  <version>Any version after 3.0</version>
</dependency>

Code Changes : Add singleton for ServerCacheFeature in your application class.

singletons.add(new ServerCacheFeature());

Add this annotation to your function :

@Cache(maxAge=15, mustRevalidate = false, noStore = false, proxyRevalidate = false, sMaxAge = 15)

noStore can be use to enable/disable to cache resp

Abhilash Kant
  • 358
  • 1
  • 2
  • 10