Uploaded image for project: 'PUBLIC - Liferay Faces'
  1. PUBLIC - Liferay Faces
  2. FACES-3183

Create Cache and CacheFactory utilities

    Description

    In the Liferay Faces codebase, ConcurrentHashMap is often used to cache values in a thread-safe way. This has lead to minor inconsistencies such as certain caches being limited by a hard-coded upper limit while other caches have no limit at all and certain caches utilizing the first computed value while others use the last computed value.

    In order to make cache usage consistent, a Cache interface, CacheImpl default implementation, and CacheFactory abstract class should be created in Liferay Faces Util. The cache can utilize ConcurrentHashMap under the hood in order to avoid external dependencies.* The Cache interface may or may not expose all the methods of ConcurrentHashMap , but it should provide at least one method to ensure that caching values is consistent across the codebase. For example:

    // Interface:
    public V cacheValue(K key, V value);
    
    // Implementation:
    public V cacheValue(K key, V value) {
    
        V retValue = concurrentHashMap.putIfAbsent(key, value);
    
        // This thread has added the value.
        if (retValue == null) {
            retValue = value;
        }
        // Otherwise, another thread already added the value and retValue contains the first added value.
    
        return retValue;
    }
    

    The interface should also require that the implementation check a provided init-param /context-param to detect the max allowed size of the cache.

    * An optional implementation utilizing Google Guava's popular Cache.java could even be provided if Guava is detected.

      Attachments

        Activity

          People

          • Assignee:
            kyle.stiemann Kyle Stiemann (Inactive)
            Reporter:
            kyle.stiemann Kyle Stiemann (Inactive)
            Participants of an Issue:
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Packages

              Version Package
              alloy-2.0.1
              util-1.1.0
              util-2.1.0
              bridge-impl-2.1.0
              metal-1.0.0
              bridge-impl-3.1.0
              bridge-impl-4.1.0
              util-3.1.0
              alloy-3.0.1