All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jboss.resteasy.client.cache.MapCache Maven / Gradle / Ivy

There is a newer version: 4.0.0.Beta5
Show newest version
package org.jboss.resteasy.client.cache;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @deprecated Caching in the Resteasy client framework in resteasy-jaxrs is replaced by
 * caching in the JAX-RS 2.0 compliant resteasy-client module.
 *
 * @see org.jboss.resteasy.client.jaxrs.ResteasyClient
 * @see org.jboss.resteasy.client.jaxrs.cache.MapCache
 */
@Deprecated
public class MapCache implements BrowserCache
{
   protected Map> cache = null;

   public MapCache()
   {
      this(new ConcurrentHashMap>());
   }

   public MapCache(final Map> cache)
   {
      this.cache = cache;
   }

   protected Map> createCache()
   {
      return new ConcurrentHashMap>();
   }

   public Entry get(String key, MediaType accept)
   {
      Map parent = cache.get(key);
      if (parent == null) return null;
      return parent.get(accept.toString());
   }

   public Entry getAny(String key)
   {
      Map parent = cache.get(key);
      if (parent == null) return null;
      Iterator iterator = parent.values().iterator();
      if (iterator.hasNext()) return iterator.next();
      return null;
   }

   public Entry getEntry(String key, MediaType accept)
   {
      Map parent = cache.get(key);
      if (parent == null) return null;
      return parent.get(accept.toString());
   }

   public Entry remove(String key, MediaType type)
   {
      Map data = cache.get(key);
      if (data == null) return null;
      Entry removed = data.remove(type.toString());
      if (data.isEmpty())
      {
         cache.remove(key);
      }
      else
      {
         cache.put(key, data);
      }
      return removed;
   }

   public void clear()
   {
      cache.clear();
   }

   public Entry put(CacheEntry cacheEntry)
   {
      Map map = cache.get(cacheEntry.getKey());
      if (map == null)
      {
         map = new ConcurrentHashMap();
      }
      map.put(cacheEntry.getMediaType().toString(), cacheEntry);
      cache.put(cacheEntry.getKey(), map);
      return cacheEntry;
   }

   public Entry put(String key, MediaType mediaType,
               MultivaluedMap headers, byte[] cached, int expires,
               String etag, String lastModified)
   {
      return put(new CacheEntry(key, headers, cached, expires, etag, lastModified, mediaType));
   }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy