1 31 32 package org.opencms.cache; 33 34 import org.opencms.file.CmsResource; 35 import org.opencms.util.CmsFileUtil; 36 37 import java.io.File ; 38 import java.io.IOException ; 39 40 59 public class CmsVfsNameBasedDiskCache { 60 61 62 private String m_rfsRepository; 63 64 70 public CmsVfsNameBasedDiskCache(String basepath, String foldername) { 71 72 m_rfsRepository = CmsFileUtil.normalizePath(basepath + foldername + File.separatorChar); 74 } 75 76 84 public byte[] getCacheContent(String rfsName) { 85 86 try { 87 File f = new File (rfsName); 88 if (f.exists()) { 89 long age = f.lastModified(); 90 if ((System.currentTimeMillis() - age) > 3600000) { 91 f.setLastModified(System.currentTimeMillis()); 93 } 94 return CmsFileUtil.readFile(f); 95 } 96 } catch (IOException e) { 97 } 99 return null; 100 } 101 102 110 public String getCacheName(CmsResource resource, String parameters) { 111 112 String rfsName = m_rfsRepository + resource.getRootPath(); 114 String extension = CmsFileUtil.getFileExtension(rfsName); 115 116 StringBuffer buf = new StringBuffer (rfsName.length() + 24); 118 buf.append(rfsName.substring(0, rfsName.length() - extension.length())); 119 120 StringBuffer ext = new StringBuffer (48); 122 ext.append(resource.getDateLastModified()); 123 ext.append(';'); 124 ext.append(resource.getDateCreated()); 125 if (resource.getLength() > 0) { 126 ext.append(';'); 127 ext.append(resource.getLength()); 128 } 129 buf.append(ext.toString().hashCode()); 131 132 if (parameters != null) { 134 buf.append('_'); 135 buf.append(parameters.hashCode()); 136 } 137 138 buf.append(extension); 140 return buf.toString(); 141 } 142 143 148 public String getRepositoryPath() { 149 150 return m_rfsRepository; 151 } 152 153 161 public void saveCacheFile(String rfsName, byte[] content) throws IOException { 162 163 CmsVfsDiskCache.saveFile(rfsName, content); 164 } 165 } | Popular Tags |