this.user = user;
}
@SuppressWarnings("unchecked")
public static UserPrefs getPrefsForUser(User user) {
UserPrefs userPrefs = null;
String cacheKey = getCacheKeyForUser(user);
try {
MemcacheService memcache = MemcacheServiceFactory.getMemcacheService();
if (memcache.contains(cacheKey)) {
logger.warning("CACHE HIT: " + cacheKey);
userPrefs = (UserPrefs) memcache.get(cacheKey);
return userPrefs;
}
logger.warning("CACHE MISS: " + cacheKey);
// If the UserPrefs object isn't in memcache,
// fall through to the datastore.
} catch (MemcacheServiceException e) {
// If there is a problem with the cache,
// fall through to the datastore.
}
EntityManager em = EMF.get().createEntityManager();
try {
userPrefs = em.find(UserPrefs.class, user.getUserId());
if (userPrefs == null) {
userPrefs = new UserPrefs(user);
} else {
userPrefs.cacheSet();
}
} finally {
em.close();
}