Interface ICommonValuesCache

  • All Known Implementing Classes:
    CommonValuesCacheImpl

    public interface ICommonValuesCache
    An interface for a cache of code system and related token values. The cache is specialized in that it supports some specific operations to process list of objects with minimal locking. The code-systems cache can be pre-filled because it is reasonable to expect that it can be sized to accommodate every value. There are likely to be too many unique token-values to cache, so these need to be retrieved on-demand and managed as LRU.
    • Method Detail

      • updateSharedMaps

        void updateSharedMaps()
        Take the records we've touched in the current thread and update the shared LRU maps.
      • resolveCodeSystems

        void resolveCodeSystems​(java.util.Collection<ResourceTokenValueRec> tokenValues,
                                java.util.List<ResourceTokenValueRec> misses)
        Lookup all the database values we have cached for the code-system names in the given collection. Put any objects with cache misses into the corresponding miss lists (so that we know which records we need to generate inserts for)
        Parameters:
        tokenValues -
        misses - the objects we couldn't find in the cache
      • resolveTokenValues

        void resolveTokenValues​(java.util.Collection<ResourceTokenValueRec> tokenValues,
                                java.util.List<ResourceTokenValueRec> misses)
        Look up the ids for the common token values. Must be preceded by resolveCodeSystems to make sure we have code-system ids set for each record. This also means that code-systems which don't yet exist must be created before this method can be called (because we need the id)
        Parameters:
        tokenValues -
        misses - the objects we couldn't find in the cache
      • resolveCanonicalValues

        void resolveCanonicalValues​(java.util.Collection<ResourceProfileRec> profileValues,
                                    java.util.List<ResourceProfileRec> misses)
        Look up the ids for the common canonical values in the cache
        Parameters:
        profileValues - the collection of profile values containing the canonical urls
        misses - the objects we couldn't find in the cache
      • getCodeSystemId

        java.lang.Integer getCodeSystemId​(java.lang.String codeSystem)
        Look up the id of the named codeSystem
        Parameters:
        codeSystem -
        Returns:
        the database identity of the code system, or null if no record was found
      • addCodeSystem

        void addCodeSystem​(java.lang.String codeSystem,
                           int id)
        Add the id to the local cache
        Parameters:
        externalSystemName -
        id -
      • addCanonicalValue

        void addCanonicalValue​(java.lang.String url,
                               long id)
        Add the url-id mapping to the local cache
        Parameters:
        url -
        id -
      • addTokenValue

        void addTokenValue​(CommonTokenValue key,
                           long id)
        Add the CommonTokenValue and id to the local cache
        Parameters:
        key -
        id -
      • clearLocalMaps

        void clearLocalMaps()
        Clear any thread-local cache maps (probably because a transaction was rolled back)
      • reset

        void reset()
        Clear the thread-local and shared caches (for test purposes)
      • prefillCodeSystems

        void prefillCodeSystems​(java.util.Map<java.lang.String,​java.lang.Integer> codeSystems)
        Add the contents of the given codeSystems map to the shared cache. It is assumed that all of these ids are already committed in the database, not newly inserted as part of the current transaction.
        Parameters:
        codeSystems -
      • getCommonTokenValueId

        java.lang.Long getCommonTokenValueId​(java.lang.String codeSystem,
                                             java.lang.String tokenValue)
        Get the database common_token_value_id for the given code system and token value.
        Parameters:
        codeSystem -
        tokenValue -
        Returns:
      • resolveCommonTokenValueIds

        java.util.Set<java.lang.Long> resolveCommonTokenValueIds​(java.util.Collection<CommonTokenValue> tokenValues,
                                                                 java.util.Set<CommonTokenValue> misses)
        Get the database common_token_value_ids for the given list of token values.
        Parameters:
        tokenValues -
        misses - the set of the CommonTokenValue objects we couldn't find in the cache
        Returns:
      • getCanonicalId

        java.lang.Long getCanonicalId​(java.lang.String url)
        Get the cached database id for the given canonical url
        Parameters:
        url -
        Returns: