+ public Image getSourceCover(String source) throws IOException {
+ Image custom = getCustomSourceCover(source);
+ if (custom != null) {
+ return custom;
+ }
+
+ Image cached = cacheLib.getSourceCover(source);
+ if (cached != null) {
+ return cached;
+ }
+
+ return lib.getSourceCover(source);
+ }
+
+ @Override
+ public Image getAuthorCover(String author) throws IOException {
+ Image custom = getCustomAuthorCover(author);
+ if (custom != null) {
+ return custom;
+ }
+
+ Image cached = cacheLib.getAuthorCover(author);
+ if (cached != null) {
+ return cached;
+ }
+
+ return lib.getAuthorCover(author);
+ }
+
+ @Override
+ public Image getCustomSourceCover(String source) throws IOException {
+ Image custom = cacheLib.getCustomSourceCover(source);
+ if (custom == null) {
+ custom = lib.getCustomSourceCover(source);
+ if (custom != null) {
+ cacheLib.setSourceCover(source, custom);
+ }
+ }
+
+ return custom;
+ }
+
+ @Override
+ public Image getCustomAuthorCover(String author) throws IOException {
+ Image custom = cacheLib.getCustomAuthorCover(author);
+ if (custom == null) {
+ custom = lib.getCustomAuthorCover(author);
+ if (custom != null) {
+ cacheLib.setAuthorCover(author, custom);
+ }
+ }
+
+ return custom;
+ }
+
+ @Override
+ public void setSourceCover(String source, String luid) throws IOException {
+ lib.setSourceCover(source, luid);
+ cacheLib.setSourceCover(source, getCover(luid));
+ }
+
+ @Override
+ 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) {
+ synchronized (metasLock) {
+ 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) {
+ synchronized (metasLock) {
+ 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) {
+ synchronized (metasLock) {
+ for (int i = 0; i < metas.size(); i++) {
+ if (metas.get(i).getLuid().equals(luid)) {
+ metas.remove(i--);
+ }
+ }
+ }
+ }