* make caching more resilient against class-version upgrades (just fail silently, don't break things)
This commit is contained in:
parent
09621b6b31
commit
137640f244
|
@ -104,7 +104,7 @@ public abstract class AbstractEpisodeListProvider implements EpisodeListProvider
|
|||
try {
|
||||
cache.put(new Element(new Key(id, normalize(query), locale), value.toArray(new SearchResult[0])));
|
||||
} catch (Exception e) {
|
||||
Logger.getLogger(AbstractEpisodeListProvider.class.getName()).log(Level.WARNING, e.getMessage(), e);
|
||||
Logger.getLogger(AbstractEpisodeListProvider.class.getName()).log(Level.WARNING, e.getMessage());
|
||||
}
|
||||
|
||||
return value;
|
||||
|
@ -129,7 +129,7 @@ public abstract class AbstractEpisodeListProvider implements EpisodeListProvider
|
|||
try {
|
||||
cache.put(new Element(new Key(id, key, sortOrder, locale), episodes.toArray(new Episode[0])));
|
||||
} catch (Exception e) {
|
||||
Logger.getLogger(AbstractEpisodeListProvider.class.getName()).log(Level.WARNING, e.getMessage(), e);
|
||||
Logger.getLogger(AbstractEpisodeListProvider.class.getName()).log(Level.WARNING, e.getMessage());
|
||||
}
|
||||
|
||||
return episodes;
|
||||
|
@ -154,7 +154,7 @@ public abstract class AbstractEpisodeListProvider implements EpisodeListProvider
|
|||
try {
|
||||
cache.put(new Element(new Key(id, category, locale, key), object));
|
||||
} catch (Exception e) {
|
||||
Logger.getLogger(AbstractEpisodeListProvider.class.getName()).log(Level.WARNING, e.getMessage(), e);
|
||||
Logger.getLogger(AbstractEpisodeListProvider.class.getName()).log(Level.WARNING, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,17 +40,21 @@ public abstract class CachedResource<T extends Serializable> {
|
|||
|
||||
public synchronized T get() throws IOException {
|
||||
String cacheKey = type.getName() + ":" + resource.toString();
|
||||
Element element = null;
|
||||
long lastUpdateTime = 0;
|
||||
|
||||
Element element = cache.get(cacheKey);
|
||||
long lastUpdateTime = (element != null) ? element.getLatestOfCreationAndUpdateTime() : 0;
|
||||
try {
|
||||
element = cache.get(cacheKey);
|
||||
if (element != null) {
|
||||
lastUpdateTime = element.getLatestOfCreationAndUpdateTime();
|
||||
}
|
||||
|
||||
// fetch from cache
|
||||
if (element != null && System.currentTimeMillis() - lastUpdateTime < expirationTime) {
|
||||
try {
|
||||
return type.cast(element.getValue());
|
||||
} catch (Exception e) {
|
||||
Logger.getLogger(getClass().getName()).log(Level.WARNING, e.getMessage(), e);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Logger.getLogger(getClass().getName()).log(Level.WARNING, e.getMessage());
|
||||
}
|
||||
|
||||
// fetch and process resource
|
||||
|
@ -64,9 +68,13 @@ public abstract class CachedResource<T extends Serializable> {
|
|||
}
|
||||
}
|
||||
|
||||
// update cached data and last-updated time
|
||||
try {
|
||||
cache.put(element);
|
||||
return type.cast(element.getValue());
|
||||
} catch (Exception e) {
|
||||
Logger.getLogger(getClass().getName()).log(Level.WARNING, e.getMessage());
|
||||
}
|
||||
|
||||
// update cached data and last-updated time
|
||||
return type.cast(element.getValue());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue