X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Flibrary%2FCacheLibrary.java;h=62ac9fa77bb4f3f7efd4a463863896961ce7abce;hb=e6249b0f26fd3a7ec4cf5e49ba9f9939018c43d3;hp=40128979ee4dcfdf318272077a99c014ab396097;hpb=ff05b8284e6e415b13d3543650075d0f7cd27ff5;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/library/CacheLibrary.java b/src/be/nikiroo/fanfix/library/CacheLibrary.java index 4012897..62ac9fa 100644 --- a/src/be/nikiroo/fanfix/library/CacheLibrary.java +++ b/src/be/nikiroo/fanfix/library/CacheLibrary.java @@ -45,6 +45,11 @@ public class CacheLibrary extends BasicLibrary { return lib.getLibraryName(); } + @Override + public Status getStatus() { + return lib.getStatus(); + } + @Override protected List getMetas(Progress pg) { if (pg == null) { @@ -78,11 +83,9 @@ public class CacheLibrary extends BasicLibrary { try { cacheLib.imprt(lib, luid, pgImport); pgImport.done(); - Story story = cacheLib.getStory(luid, pgGet); - metas.remove(story.getMeta()); - metas.add(story.getMeta()); + clearCache(); } catch (IOException e) { - Instance.syserr(e); + Instance.getTraceHandler().error(e); } pgImport.done(); @@ -98,14 +101,26 @@ public class CacheLibrary extends BasicLibrary { @Override public BufferedImage getCover(final String luid) { - // Retrieve it from the cache if possible: if (isCached(luid)) { return cacheLib.getCover(luid); } + // We could update the cache here, but it's not easy return lib.getCover(luid); } + @Override + public BufferedImage getSourceCover(String source) { + // no cache for the source cover + return lib.getSourceCover(source); + } + + @Override + public void setSourceCover(String source, String luid) { + lib.setSourceCover(source, luid); + cacheLib.setSourceCover(source, getSourceCover(source)); + } + @Override protected void clearCache() { metas = null; @@ -116,24 +131,34 @@ public class CacheLibrary extends BasicLibrary { @Override public synchronized Story save(Story story, String luid, Progress pg) throws IOException { - story = lib.save(story, luid, pg); + Progress pgLib = new Progress(); + Progress pgCacheLib = new Progress(); + + if (pg == null) { + pg = new Progress(); + } + + pg.setMinMax(0, 2); + pg.addProgress(pgLib, 1); + pg.addProgress(pgCacheLib, 1); + + story = lib.save(story, luid, pgLib); + story = cacheLib.save(story, luid, pgCacheLib); + clearCache(); + return story; } @Override public synchronized void delete(String luid) throws IOException { - cacheLib.delete(luid); + if (isCached(luid)) { + cacheLib.delete(luid); + } lib.delete(luid); clearCache(); } - @Override - public void setSourceCover(String source, String luid) { - cacheLib.setSourceCover(source, luid); - lib.setSourceCover(source, luid); - } - @Override public synchronized void changeSource(String luid, String newSource, Progress pg) throws IOException { @@ -147,7 +172,9 @@ public class CacheLibrary extends BasicLibrary { pg.addProgress(pgCache, 1); pg.addProgress(pgOrig, 1); - cacheLib.changeSource(luid, newSource, pgCache); + if (isCached(luid)) { + cacheLib.changeSource(luid, newSource, pgCache); + } pgCache.done(); lib.changeSource(luid, newSource, pgOrig); pgOrig.done(); @@ -178,8 +205,10 @@ public class CacheLibrary extends BasicLibrary { * in case of I/O error */ public void clearFromCache(String luid) throws IOException { - cacheLib.delete(luid); - clearCache(); + if (isCached(luid)) { + cacheLib.delete(luid); + clearCache(); + } } // All the following methods are only used by Save and Delete in