KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jdon > controller > cache > LRUCache


1 /**
2  * Copyright 2003-2006 the original author or authors.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6
7        http://www.apache.org/licenses/LICENSE-2.0
8
9   * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */

15
16 package com.jdon.controller.cache;
17
18 import com.jdon.util.PropsUtil;
19 import com.jdon.util.UtilCache;
20
21  /**
22   * the LRU Cache implemention.
23   * default is OFBiz's UtilCache, we can replace it with better cache product.
24   *
25   * cache parameters must be defined, and the configure file name must
26   * be defined in container.xml too.
27   * <p>@author <a HREF="mailto:banqiao@jdon.com">banq</a></p>
28   */

29 public class LRUCache implements Cache {
30   
31   private UtilCache cache;
32
33   /**
34    * configFileName must be defined in container.xml
35    *
36    * @param configFileName
37    */

38   public LRUCache(String JavaDoc configFileName) {
39     PropsUtil propsUtil = new PropsUtil(configFileName);
40     cache = new UtilCache(propsUtil);
41   }
42
43   public Object JavaDoc get(Object JavaDoc key) {
44     return cache.get(key);
45   }
46
47   public void put(Object JavaDoc key, Object JavaDoc value) {
48     cache.put(key, value);
49   }
50
51   public void remove(Object JavaDoc key) {
52     cache.remove(key);
53   }
54
55   public long size() {
56     return cache.size();
57   }
58
59   public void clear() {
60     cache.clear();
61   }
62
63   public boolean contain(Object JavaDoc key) {
64     return cache.containsKey(key);
65   }
66
67 }
68
Popular Tags