Source code: com/opencms/template/cache/CmsUriLocator.java
1 /*
2 * File : $Source: /usr/local/cvs/opencms/src/com/opencms/template/cache/CmsUriLocator.java,v $
3 * Date : $Date: 2003/01/20 23:59:21 $
4 * Version: $Revision: 1.9 $
5 *
6 * This library is part of OpenCms -
7 * the Open Source Content Mananagement System
8 *
9 * Copyright (C) 2001 The OpenCms Group
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * For further information about OpenCms, please see the
22 * OpenCms Website: http://www.opencms.org
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 */
28
29 package com.opencms.template.cache;
30
31 import java.util.Vector;
32
33 /**
34 * The UriLocator is used to receive CmsUri-Objects. It is the Cache for these
35 * CmsUri-Objects. The CmsUri-Objects are stored in memory or - if they are not
36 * used a long time written to an external database. The locator manages all the
37 * reading, writing and management of the CmsUri's.
38 *
39 * @author Andreas Schouten
40 */
41 public class CmsUriLocator {
42
43 /**
44 * A hashtable to store the uri's.
45 */
46 private CmsLruCache m_uris;
47
48 /**
49 * The default constructor for this locator.
50 */
51 CmsUriLocator(int cacheSize) {
52 if(cacheSize < 2){
53 cacheSize = 10000;
54 }
55 m_uris = new CmsLruCache(cacheSize);
56 }
57
58 /**
59 * Adds a new Uri to this locator.
60 * @param descriptor - the UriDescriptor for this uri.
61 * @param uri - the Uri to put in this locator.
62 */
63 public void put(CmsUriDescriptor desc, CmsUri uri) {
64 m_uris.put(desc, uri);
65 }
66
67 /**
68 * Gets a uri from this locator.
69 * @param desc - the descriptor to locate the uri.
70 * @return the uri that was found.
71 */
72 public CmsUri get(CmsUriDescriptor desc) {
73 return (CmsUri) m_uris.get(desc);
74 }
75
76 /**
77 * Deletes all invalid uris from cache.
78 * @param invalidUris A Vector with the names of the uris (String) to be deleted from cache.
79 */
80 public void deleteUris(Vector invalidUris){
81 for (int i = 0; i < invalidUris.size(); i++){
82 m_uris.deleteUri((String)invalidUris.elementAt(i));
83 }
84 }
85
86 /**
87 * Clears the cache compleatly.
88 */
89 public void clearCache(){
90 m_uris.clearCache();
91 }
92
93 /**
94 * Gets the Information of max size and size for the cache.
95 *
96 * @return a Vector whith informations about the size of the cache.
97 */
98 public Vector getCacheInfo(){
99 return m_uris.getCacheInfo();
100 }
101
102 }