@Override public Void call() { similarityCache.clear(); return null; } });
@Override public long[] getUserNeighborhood(long userID) throws TasteException { return neighborhoodCache.get(userID); }
/** * <p> * Clears cached recommendations for the given user. * </p> * * @param userID * clear cached data associated with this user ID */ public void clear(final long userID) { log.debug("Clearing recommendations for user ID '{}'", userID); recommendationCache.remove(userID); estimatedPrefCache.removeKeysMatching(new Cache.MatchPredicate<LongPair>() { @Override public boolean matches(LongPair userItemPair) { return userItemPair.getFirst() == userID; } }); }
@Test public void testMixedUsage() throws TasteException { Random random = RandomUtils.getRandom(); Retriever<Object,Object> retriever = new IdentityRetriever(); Cache<Object,Object> cache = new Cache<Object,Object>(retriever, 1000); for (int i = 0; i < 1000000; i++) { double r = random.nextDouble(); if (r < 0.01) { cache.clear(); } else if (r < 0.1) { cache.remove(r - 100); } else { assertEquals(i, cache.get(i)); } } }
public CachingUserNeighborhood(UserNeighborhood neighborhood, DataModel dataModel) throws TasteException { Preconditions.checkArgument(neighborhood != null, "neighborhood is null"); this.neighborhood = neighborhood; int maxCacheSize = dataModel.getNumUsers(); // just a dumb heuristic for sizing this.neighborhoodCache = new Cache<Long,long[]>(new NeighborhoodRetriever(neighborhood), maxCacheSize); }
public void clearCacheForItem(long itemID) { similarityCache.removeKeysMatching(new LongPairMatchPredicate(itemID)); }
/** * <p> * Returns cached value for a key. If it does not exist, it is loaded using a {@link Retriever}. * </p> * * @param key * cache key * @return value for that key * @throws TasteException * if an exception occurs while retrieving a new cached value */ @Override public V get(K key) throws TasteException { V value; synchronized (cache) { value = cache.get(key); } if (value == null) { return getAndCacheValue(key); } return value == NULL ? null : value; }
public CachingUserNeighborhood(UserNeighborhood neighborhood, DataModel dataModel) throws TasteException { Preconditions.checkArgument(neighborhood != null, "neighborhood is null"); this.neighborhood = neighborhood; int maxCacheSize = dataModel.getNumUsers(); // just a dumb heuristic for sizing this.neighborhoodCache = new Cache<Long,long[]>(new NeighborhoodRetriever(neighborhood), maxCacheSize); }
public void clearCacheForUser(long userID) { similarityCache.removeKeysMatching(new LongPairMatchPredicate(userID)); }
/** * <p> * Returns cached value for a key. If it does not exist, it is loaded using a {@link Retriever}. * </p> * * @param key * cache key * @return value for that key * @throws TasteException * if an exception occurs while retrieving a new cached value */ @Override public V get(K key) throws TasteException { V value; synchronized (cache) { value = cache.get(key); } if (value == null) { return getAndCacheValue(key); } return value == NULL ? null : value; }
@Override public Void call() { similarityCache.clear(); return null; } });
@Override public float inferPreference(long userID, long itemID) throws TasteException { return averagePreferenceValue.get(userID); }
public CachingUserNeighborhood(UserNeighborhood neighborhood, DataModel dataModel) throws TasteException { Preconditions.checkArgument(neighborhood != null, "neighborhood is null"); this.neighborhood = neighborhood; int maxCacheSize = dataModel.getNumUsers(); // just a dumb heuristic for sizing this.neighborhoodCache = new Cache<>(new NeighborhoodRetriever(neighborhood), maxCacheSize); }
/** * <p> * Clears cached recommendations for the given user. * </p> * * @param userID * clear cached data associated with this user ID */ public void clear(final long userID) { log.debug("Clearing recommendations for user ID '{}'", userID); recommendationCache.remove(userID); estimatedPrefCache.removeKeysMatching(new Cache.MatchPredicate<LongPair>() { @Override public boolean matches(LongPair userItemPair) { return userItemPair.getFirst() == userID; } }); }
public void clearCacheForItem(long itemID) { similarityCache.removeKeysMatching(new LongPairMatchPredicate(itemID)); }
/** * <p> * Returns cached value for a key. If it does not exist, it is loaded using a {@link Retriever}. * </p> * * @param key * cache key * @return value for that key * @throws TasteException * if an exception occurs while retrieving a new cached value */ @Override public V get(K key) throws TasteException { V value; synchronized (cache) { value = cache.get(key); } if (value == null) { return getAndCacheValue(key); } return value == NULL ? null : value; }
@Override public Void call() { similarityCache.clear(); return null; } });
@Override public long[] getUserNeighborhood(long userID) throws TasteException { return neighborhoodCache.get(userID); }
public AveragingPreferenceInferrer(DataModel dataModel) throws TasteException { this.dataModel = dataModel; Retriever<Long,Float> retriever = new PrefRetriever(); averagePreferenceValue = new Cache<Long,Float>(retriever, dataModel.getNumUsers()); refresh(null); }