| 1 16 package org.outerj.daisy.frontend.util; 17 18 import org.apache.excalibur.store.Store; 19 import org.apache.excalibur.source.Source; 20 import org.apache.excalibur.source.SourceValidity; 21 22 import java.io.IOException ; 23 24 public class CacheHelper { 25 public static Object getFromCache(Store store, Source source, String prefix) { 26 String key = prefix + source.getURI(); 27 SourceValidity newValidity = source.getValidity(); 28 29 if (newValidity == null) { 31 store.remove(key); 32 return null; 33 } 34 35 Object [] objectAndValidity = (Object []) store.get(key); 37 if (objectAndValidity == null) { 38 return null; 39 } 40 41 SourceValidity storedValidity = (SourceValidity) objectAndValidity[1]; 43 int valid = storedValidity.isValid(); 44 boolean isValid; 45 if (valid == SourceValidity.UNKNOWN) { 46 valid = storedValidity.isValid(newValidity); 47 isValid = (valid == SourceValidity.VALID); 48 } else { 49 isValid = (valid == SourceValidity.VALID); 50 } 51 52 if (!isValid) { 54 store.remove(key); 55 return null; 56 } 57 58 return objectAndValidity[0]; 60 } 61 62 public static void setInCache(Store store, Object object, Source source, String prefix) throws IOException { 63 String key = prefix + source.getURI(); 64 SourceValidity validity = source.getValidity(); 65 if (validity != null) { 66 Object [] objectAndValidity = {object, validity}; 67 store.store(key, objectAndValidity); 68 } 69 } 70 } 71 | Popular Tags |