01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.commons.vfs.cache;
18:
19: import org.apache.commons.vfs.FileName;
20: import org.apache.commons.vfs.FileObject;
21: import org.apache.commons.vfs.FileSystem;
22:
23: import java.util.HashMap;
24: import java.util.Map;
25:
26: /**
27: * A {@link org.apache.commons.vfs.FilesCache} implementation.<br>
28: * This implementation caches every file for the complete lifetime of the used {@link org.apache.commons.vfs.FileSystemManager}.
29: *
30: * @author <a href="mailto:imario@apache.org">Mario Ivankovits</a>
31: * @version $Revision: 537936 $ $Date: 2007-05-14 11:24:35 -0700 (Mon, 14 May 2007) $
32: */
33: public class DefaultFilesCache extends AbstractFilesCache {
34: private final Map filesystemCache = new HashMap(10);
35:
36: public void putFile(final FileObject file) {
37: Map files = getOrCreateFilesystemCache(file.getFileSystem());
38: files.put(file.getName(), file);
39: }
40:
41: public FileObject getFile(final FileSystem filesystem,
42: final FileName name) {
43: Map files = getOrCreateFilesystemCache(filesystem);
44: return (FileObject) files.get(name);
45: }
46:
47: public void clear(FileSystem filesystem) {
48: Map files = getOrCreateFilesystemCache(filesystem);
49: files.clear();
50: }
51:
52: protected Map getOrCreateFilesystemCache(FileSystem filesystem) {
53: Map files = (Map) filesystemCache.get(filesystem);
54: if (files == null) {
55: files = new HashMap();
56: filesystemCache.put(filesystem, files);
57: }
58:
59: return files;
60: }
61:
62: public void close() {
63: super .close();
64:
65: filesystemCache.clear();
66: }
67:
68: public void removeFile(FileSystem filesystem, FileName name) {
69: Map files = getOrCreateFilesystemCache(filesystem);
70: files.remove(name);
71: }
72:
73: public void touchFile(FileObject file) {
74: }
75: }
|