01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. The ASF licenses this file to You
04: * under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License. For additional information regarding
15: * copyright in this work, please see the NOTICE file in the top level
16: * directory of this distribution.
17: */
18:
19: package org.apache.roller.util.cache;
20:
21: import java.util.Map;
22: import org.apache.commons.logging.Log;
23: import org.apache.commons.logging.LogFactory;
24:
25: /**
26: * Roller Expiring LRU cache factory.
27: */
28: public class ExpiringLRUCacheFactoryImpl implements CacheFactory {
29:
30: private static Log log = LogFactory
31: .getLog(ExpiringLRUCacheFactoryImpl.class);
32:
33: // protected so only the CacheManager can instantiate us
34: protected ExpiringLRUCacheFactoryImpl() {
35: }
36:
37: /**
38: * Construct a new instance of a Roller Expiring LRUCache.
39: */
40: public Cache constructCache(Map properties) {
41:
42: int size = 100;
43: long timeout = 15 * 60;
44: String id = "unknown";
45:
46: try {
47: size = Integer.parseInt((String) properties.get("size"));
48: } catch (Exception e) {
49: // ignored
50: }
51:
52: try {
53: timeout = Long
54: .parseLong((String) properties.get("timeout"));
55: } catch (Exception e) {
56: // ignored
57: }
58:
59: String cacheId = (String) properties.get("id");
60: if (cacheId != null) {
61: id = cacheId;
62: }
63:
64: Cache cache = new ExpiringLRUCacheImpl(id, size, timeout);
65:
66: log.debug("new cache constructed. size=" + size + ", timeout="
67: + timeout);
68:
69: return cache;
70: }
71:
72: }
|