mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
added in memory cache and redis cache and marked them as application scoped
This commit is contained in:
@@ -1,31 +1,21 @@
|
||||
package com.commafeed.backend.cache;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
|
||||
import com.commafeed.backend.model.Feed;
|
||||
import com.commafeed.backend.model.FeedEntry;
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
|
||||
public class CacheService {
|
||||
public abstract class CacheService {
|
||||
|
||||
Cache<String, Marker> entryCache = CacheBuilder.newBuilder()
|
||||
.maximumSize(1000000).expireAfterWrite(24, TimeUnit.HOURS).build();
|
||||
public abstract List<String> getLastEntries(Feed feed);
|
||||
|
||||
private static enum Marker {
|
||||
INSTANCE
|
||||
}
|
||||
public abstract void setLastEntries(Feed feed, List<String> entries);
|
||||
|
||||
public boolean hasFeedEntry(Feed feed, FeedEntry entry) {
|
||||
return entryCache.getIfPresent(buildKey(feed, entry)) == Marker.INSTANCE;
|
||||
}
|
||||
|
||||
public void putFeedEntry(Feed feed, FeedEntry entry) {
|
||||
entryCache.put(buildKey(feed, entry), Marker.INSTANCE);
|
||||
}
|
||||
|
||||
private String buildKey(Feed feed, FeedEntry entry) {
|
||||
return String.format("%s:%s:%s", feed.getId(), entry.getGuid(),
|
||||
public String buildKey(Feed feed, FeedEntry entry) {
|
||||
return DigestUtils.sha1Hex(entry.getGuid() +
|
||||
entry.getUrl());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user