mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-24 08:48:51 -05:00
* 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 {
|
try {
|
||||||
cache.put(new Element(new Key(id, normalize(query), locale), value.toArray(new SearchResult[0])));
|
cache.put(new Element(new Key(id, normalize(query), locale), value.toArray(new SearchResult[0])));
|
||||||
} catch (Exception e) {
|
} 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;
|
return value;
|
||||||
@ -129,7 +129,7 @@ public abstract class AbstractEpisodeListProvider implements EpisodeListProvider
|
|||||||
try {
|
try {
|
||||||
cache.put(new Element(new Key(id, key, sortOrder, locale), episodes.toArray(new Episode[0])));
|
cache.put(new Element(new Key(id, key, sortOrder, locale), episodes.toArray(new Episode[0])));
|
||||||
} catch (Exception e) {
|
} 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;
|
return episodes;
|
||||||
@ -154,7 +154,7 @@ public abstract class AbstractEpisodeListProvider implements EpisodeListProvider
|
|||||||
try {
|
try {
|
||||||
cache.put(new Element(new Key(id, category, locale, key), object));
|
cache.put(new Element(new Key(id, category, locale, key), object));
|
||||||
} catch (Exception e) {
|
} 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 {
|
public synchronized T get() throws IOException {
|
||||||
String cacheKey = type.getName() + ":" + resource.toString();
|
String cacheKey = type.getName() + ":" + resource.toString();
|
||||||
|
Element element = null;
|
||||||
|
long lastUpdateTime = 0;
|
||||||
|
|
||||||
Element element = cache.get(cacheKey);
|
try {
|
||||||
long lastUpdateTime = (element != null) ? element.getLatestOfCreationAndUpdateTime() : 0;
|
element = cache.get(cacheKey);
|
||||||
|
if (element != null) {
|
||||||
// fetch from cache
|
lastUpdateTime = element.getLatestOfCreationAndUpdateTime();
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fetch from cache
|
||||||
|
if (element != null && System.currentTimeMillis() - lastUpdateTime < expirationTime) {
|
||||||
|
return type.cast(element.getValue());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Logger.getLogger(getClass().getName()).log(Level.WARNING, e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetch and process resource
|
// fetch and process resource
|
||||||
@ -64,9 +68,13 @@ public abstract class CachedResource<T extends Serializable> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
cache.put(element);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Logger.getLogger(getClass().getName()).log(Level.WARNING, e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
// update cached data and last-updated time
|
// update cached data and last-updated time
|
||||||
cache.put(element);
|
|
||||||
return type.cast(element.getValue());
|
return type.cast(element.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user