01: /*
02: * Created on 24-Mar-2003
03: */
04: package net.sf.jportlet.service.cache;
05:
06: /**
07: * Implementation of {@link net.sf.jportlet.service.cache.CacheableImpl}
08: *
09: * @author <a href="mailto:tchbansi@sourceforge.net">Herve Tchepannou</a>
10: */
11: public class CacheableImpl implements Cacheable {
12: //~ Instance fields --------------------------------------------------------
13:
14: private Object _id;
15: private Object _data;
16: private long _expirationTime;
17:
18: //~ Constructors -----------------------------------------------------------
19:
20: /**
21: *
22: * @param id Id of the Cacheable object
23: * @param data Data of the Cacheable object
24: * @param TTL Time to live in millis-seconds. if < 0, then the object
25: * never expires
26: */
27: public CacheableImpl(Object id, Object data, long TTL) {
28: _id = id;
29: _data = data;
30: _expirationTime = (TTL >= 0) ? (System.currentTimeMillis() + TTL)
31: : (-1);
32: }
33:
34: //~ Methods ----------------------------------------------------------------
35:
36: /**
37: * @see net.sf.jportlet.service.cache.Cacheable#getData()
38: */
39: public Object getData() {
40: return _data;
41: }
42:
43: /**
44: * @see net.sf.jportlet.service.cache.Cacheable#getId()
45: */
46: public Object getId() {
47: return _id;
48: }
49:
50: /**
51: * @see net.sf.jportlet.service.cache.Cacheable#isExpired()
52: */
53: public boolean isExpired() {
54: return (_expirationTime >= 0) ? (System.currentTimeMillis() > _expirationTime)
55: : false;
56: }
57:
58: /**
59: * @see net.sf.jportlet.service.cache.Cacheable#expire()
60: */
61: public void expire() {
62: _expirationTime = 0;
63: }
64: }
|