| CacheKeyGeneratorUtil.java |
1 /**
2 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License as published by the Free
6 * Software Foundation; either version 2.1 of the License, or (at your option)
7 * any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 * details.
13 */
14
15 package com.liferay.portal.kernel.cache.key;
16
17 import java.util.HashMap;
18 import java.util.Map;
19
20 /**
21 * <a href="CacheKeyGeneratorUtil.java.html"><b><i>View Source</i></b></a>
22 *
23 * @author Michael C. Han
24 */
25 public class CacheKeyGeneratorUtil {
26
27 public static String getCacheKey(String cacheName, String key) {
28 CacheKeyGenerator cacheKeyGenerator = _cacheKeyGenerators.get(
29 cacheName);
30
31 if (cacheKeyGenerator == null) {
32 cacheKeyGenerator = _defaultCacheKeyGenerator;
33 }
34
35 if (cacheKeyGenerator != null) {
36 return cacheKeyGenerator.getCacheKey(key);
37 }
38
39 return key;
40 }
41
42 public void setCacheKeyGenerators(
43 Map<String, CacheKeyGenerator> cacheKeyGenerators) {
44
45 _cacheKeyGenerators = cacheKeyGenerators;
46 }
47
48 public void setDefaultCacheKeyGenerator(
49 CacheKeyGenerator defaultCacheKeyGenerator) {
50
51 _defaultCacheKeyGenerator = defaultCacheKeyGenerator;
52 }
53
54 private static Map<String, CacheKeyGenerator> _cacheKeyGenerators =
55 new HashMap<String, CacheKeyGenerator>();
56 private static CacheKeyGenerator _defaultCacheKeyGenerator;
57
58 }