Example usage for org.apache.mahout.cf.taste.impl.common Cache Cache

List of usage examples for org.apache.mahout.cf.taste.impl.common Cache Cache

Introduction

In this page you can find the example usage for org.apache.mahout.cf.taste.impl.common Cache Cache.

Prototype

public Cache(Retriever<? super K, ? extends V> retriever, int maxEntries) 

Source Link

Document

Creates a new cache based on the given Retriever and with given maximum size.

Usage

From source file:net.ufida.info.mahout.common.CachingRecommender.java

License:Apache License

public CachingRecommender(Recommender recommender) throws TasteException {
    Preconditions.checkArgument(recommender != null, "recommender is null");
    this.recommender = recommender;
    maxHowMany = new int[] { 1 };
    // Use "num users" as an upper limit on cache size. Rough guess.
    int numUsers = recommender.getDataModel().getNumUsers();
    recommendationsRetriever = new RecommendationRetriever();
    recommendationCache = new Cache<Long, Recommendations>(recommendationsRetriever, numUsers);
    estimatedPrefCache = new Cache<LongPair, Float>(new EstimatedPrefRetriever(), numUsers);
    refreshHelper = new RefreshHelper(new Callable<Object>() {
        @Override//from  w ww. ja  va 2  s  . co  m
        public Object call() {
            clear();
            return null;
        }
    });
    refreshHelper.addDependency(recommender);
}