Skip to content

Commit

Permalink
KNL-1408 Don't cache preferences in the session
Browse files Browse the repository at this point in the history
We're already storing them in the system-wide cache, which should be
fast enough.
  • Loading branch information
marktriggs committed Feb 3, 2016
1 parent 5ec4517 commit 6812cb4
Showing 1 changed file with 2 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ public abstract class BasePreferencesService implements PreferencesService, Sing
protected Storage m_storage = null;
/** The initial portion of a relative access point URL. */
protected String m_relativeAccessPoint = null;
/** The session cache variable for current user's preferences */
protected String ATTR_PREFERENCE = "attr_preference";
/** the cache for Preference objects **/
private Cache m_cache;
/**********************************************************************************************************************************************************************************************************************************************************
Expand Down Expand Up @@ -328,12 +326,6 @@ public void commit(PreferencesEdit edit)
SessionManager sManager = sessionManager();
Session s = sManager.getCurrentSession();

// update the session cache if the preference is for current session user
if (sManager.getCurrentSessionUserId().equals(edit.getId()))
{
s.setAttribute(ATTR_PREFERENCE, new BasePreferences((BasePreferences) edit));
}

// track it
eventTrackingService()
.post(eventTrackingService().newEvent(((BasePreferences) edit).getEvent(), edit.getReference(), true));
Expand Down Expand Up @@ -412,7 +404,7 @@ public void remove(PreferencesEdit edit)
}

/**
* Find the preferences object, in the user's session, cache or storage.
* Find the preferences object in cache or storage.
*
* @param id
* The preferences id.
Expand All @@ -424,20 +416,7 @@ protected BasePreferences findPreferences(String id)
return null;
}

boolean isForCurrentUser = id.equals(sessionManager().getCurrentSessionUserId());
Session session = sessionManager().getCurrentSession();

// If we're getting the preferences for the current user, we can use the
// version stored in the session if present.
if (isForCurrentUser) {
BasePreferences prefsFromSession = (BasePreferences) session.getAttribute(ATTR_PREFERENCE);

if (prefsFromSession != null) {
return new BasePreferences(prefsFromSession);
}
}

// Otherwise, try the cache
// Try the cache
BasePreferences prefs = (BasePreferences) m_cache.get(id);

// Failing that, try the storage
Expand All @@ -446,13 +425,7 @@ protected BasePreferences findPreferences(String id)
}

if (prefs != null) {
// Refresh the cache
m_cache.put(id, prefs);

// And stash preferences on the current user's session if appropriate.
if (isForCurrentUser) {
session.setAttribute(ATTR_PREFERENCE, new BasePreferences(prefs));
}
}

return prefs;
Expand Down

0 comments on commit 6812cb4

Please sign in to comment.