1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package nl.hippo.portal.cms.cache;
17
18 import java.io.IOException;
19
20 import nl.hippo.client.api.caching.CachedResponse;
21 import nl.hippo.client.api.caching.CachedResponseImpl;
22 import nl.hippo.client.api.event.EventValidity;
23 import nl.hippo.client.api.service.CachingService;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27
28 /***
29 * @author <a href="mailto:d.dam@hippo.nl">Dennis Dam</a>
30 *
31 * @version $Id: ObjectCacheImpl.java 6523 2007-05-22 13:20:55Z ddam $
32 */
33 public class ObjectCacheImpl implements ObjectCache {
34
35 private static final Log log = LogFactory.getLog(ObjectCacheImpl.class);
36
37 private CachingService service;
38 private CacheKeyFactory keyFactory;
39 private EventValidityFactory eventValidityFactory;
40
41 public ObjectCacheImpl(CachingService service){
42 this.service = service;
43 this.keyFactory = new PortalCacheKeyFactoryImpl();
44 this.eventValidityFactory = new EventValidityFactoryImpl();
45 }
46
47 public Object get(PortalCacheKey cacheKey) {
48 Object o = service.get(cacheKey);
49 if (o instanceof CachedResponse){
50 o = ((CachedResponse) o).getResponse();
51 }
52 return o;
53 }
54
55 public void store(PortalCacheKey cacheKey, Object value, EventValidity validity) {
56 store(cacheKey, value, new EventValidity[]{validity});
57 }
58
59 public void store(PortalCacheKey cacheKey, Object value, EventValidity[] validities) {
60 if (value == null) {
61 throw new IllegalArgumentException("object may not be null");
62 }
63 try {
64 CachedResponse cr = new CachedResponseImpl(validities, value);
65 service.store(cacheKey, cr);
66 } catch (IOException e) {
67 log.error("Exception while storing object: ", e);
68 }
69 }
70
71 public CacheKeyFactory getCacheKeyFactory(){
72 return this.keyFactory;
73 }
74
75 public EventValidityFactory getEventValidityFactory(){
76 return this.eventValidityFactory;
77 }
78
79 }