Class CachedPreference

  • All Implemented Interfaces:
    Serializable

    @SessionScoped
    public class CachedPreference
    extends Object
    implements Serializable
    This class is used to keep the value of some preferences in cache during the life cycle of a session, avoiding the time spent to compute the preference value. The preference values that can be cached by this class are those defined at System level.
    See Also:
    Serialized Form
    • Constructor Detail

      • CachedPreference

        public CachedPreference()
    • Method Detail

      • getPreferenceValue

        public String getPreferenceValue​(String propertyName)
        It returns a String with the value of the preference whose related property name is entered as parameter. In case the value is not stored in cache, then the value will be retrieved from database.
        Parameters:
        propertyName - The name of the property related to the preference
        Returns:
        A String with the value of the cached preference
      • getPreferenceValueAndStoreInCache

        public String getPreferenceValueAndStoreInCache​(String propertyName)
        Return the Preference value and store it into the cached variable
        Parameters:
        propertyName - The name of the property related to the preference
        Returns:
        The preference value of the propertyName given
      • isCachedPreference

        public boolean isCachedPreference​(String propertyName)
        Checks if the preference related to the property name entered as parameter is contained in the list of cached preferences.
        Parameters:
        propertyName - The name of the property related to the preference
        Returns:
        true if the preference related to the property name is a cached preference, false otherwise
      • setPreferenceValue

        public void setPreferenceValue​(String propertyName,
                                       String preferenceValue)
        Sets the cached value of the preference. This method is defined as synchronized in order to avoid concurrency problems.
        Parameters:
        propertyName - The name of the property related to the preference
        preferenceValue - String with the value assigned to the preference
      • invalidatePreferenceValue

        public void invalidatePreferenceValue​(String propertyName)
        Invalidates the cached value of the preference. This method is defined as synchronized in order to avoid concurrency problems.
        Parameters:
        propertyName - The name of the property related to the preference
      • addCachedPreference

        public void addCachedPreference​(String propertyName)
        Adds a new preference into the set of preferences whose value is stored in cache.
        Parameters:
        propertyName - The name of the property related to the preference to be cached