+ public void setAuthorCover(String author, String luid) throws IOException {
+ lib.setAuthorCover(author, luid);
+ cacheLib.setAuthorCover(author, getCover(luid));
+ }
+
+ /**
+ * Invalidate the {@link Story} cache (when the content has changed, but we
+ * already have it) with the new given meta.
+ * <p>
+ * <b>Make sure to always use {@link MetaData} from the cached library
+ * in priority, here.</b>
+ *
+ * @param meta
+ * the {@link Story} to clear from the cache
+ *
+ * @throws IOException
+ * in case of IOException
+ */
+ @Override
+ @Deprecated
+ protected void updateInfo(MetaData meta) throws IOException {
+ throw new IOException(
+ "This method is not supported in a CacheLibrary, please use updateMetaCache");
+ }
+
+ // relplace the meta in Metas by Meta, add it if needed
+ // return TRUE = added
+ private boolean updateMetaCache(List<MetaData> metas, MetaData meta) {
+ if (meta != null && metas != null) {
+ boolean changed = false;
+ for (int i = 0; i < metas.size(); i++) {
+ if (metas.get(i).getLuid().equals(meta.getLuid())) {
+ metas.set(i, meta);
+ changed = true;
+ }
+ }
+
+ if (!changed) {
+ metas.add(meta);
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ @Override
+ protected void invalidateInfo(String luid) {
+ if (luid == null) {
+ metasReal = null;
+ metasMixed = null;
+ } else {
+ invalidateInfo(metasReal, luid);
+ invalidateInfo(metasMixed, luid);
+ }
+
+ cacheLib.invalidateInfo(luid);
+ lib.invalidateInfo(luid);
+ }
+
+ // luid cannot be null
+ private void invalidateInfo(List<MetaData> metas, String luid) {
+ if (metas != null) {
+ for (int i = 0; i < metas.size(); i++) {
+ if (metas.get(i).getLuid().equals(luid)) {
+ metas.remove(i--);
+ }
+ }
+ }
+ }
+
+ @Override
+ public synchronized Story save(Story story, String luid, Progress pg) throws IOException {
+ 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);
+ updateMetaCache(metasReal, story.getMeta());
+
+ story = cacheLib.save(story, story.getMeta().getLuid(), pgCacheLib);
+ updateMetaCache(metasMixed, story.getMeta());
+
+ return story;
+ }
+
+ @Override
+ public synchronized void delete(String luid) throws IOException {
+ if (isCached(luid)) {
+ cacheLib.delete(luid);
+ }
+ lib.delete(luid);
+
+ invalidateInfo(luid);
+ }
+
+ @Override
+ protected synchronized void changeSTA(String luid, String newSource, String newTitle, String newAuthor, Progress pg)
+ throws IOException {