001    package railo.runtime.cache.legacy;
002    
003    import java.io.ByteArrayInputStream;
004    import java.io.IOException;
005    
006    import railo.commons.io.IOUtil;
007    import railo.commons.io.res.Resource;
008    import railo.runtime.type.dt.TimeSpan;
009    
010    public class FileCacheEntry implements CacheEntry {
011    
012            private static final String ENC = "utf-8";
013            private Resource res;
014            //private Resource directory;
015            //private String name,raw;
016            
017            
018            
019            private boolean isOK(TimeSpan timeSpan) {
020                    return res.exists() && (res.lastModified()+timeSpan.getMillis()>=System.currentTimeMillis());
021            }
022            public String readEntry(TimeSpan timeSpan,String defaultValue) throws IOException {
023                    if(isOK(timeSpan))
024                            return IOUtil.toString(res,ENC);
025                    return defaultValue;
026            }
027    
028            public void writeEntry(String entry,boolean append) throws IOException {
029                    IOUtil.copy(new ByteArrayInputStream(entry.getBytes(ENC)), res.getOutputStream(append),true,true);
030            }
031    
032    }