Class CacheKey

java.lang.Object
com.sap.cloud.sdk.cloudplatform.cache.CacheKey
All Implemented Interfaces:
GenericCacheKey<CacheKey,Object>

public final class CacheKey extends Object implements GenericCacheKey<CacheKey,Object>
CacheKey with either global visibility, tenant isolation, or tenant and principal isolation.
  • Method Details

    • getTenantId

      @Nonnull public io.vavr.control.Option<String> getTenantId()
      Description copied from interface: GenericCacheKey
      Getter for the Id of the tenant for which the key is used.
      Specified by:
      getTenantId in interface GenericCacheKey<CacheKey,Object>
      Returns:
      The tenant identifier.
    • getPrincipalId

      @Nonnull public io.vavr.control.Option<String> getPrincipalId()
      Description copied from interface: GenericCacheKey
      Getter for the name of the principal for which the key is used.
      Specified by:
      getPrincipalId in interface GenericCacheKey<CacheKey,Object>
      Returns:
      The principal identifier.
    • append

      @Nonnull public CacheKey append(@Nonnull Iterable<Object> objects) throws IllegalArgumentException
      Description copied from interface: GenericCacheKey
      Appends the given Objects to this instance. In order to compare cache keys, Object.equals(Object) and Object.hashCode() are used. The given objects must not be null.
      Specified by:
      append in interface GenericCacheKey<CacheKey,Object>
      Parameters:
      objects - Additional objects that should be used to identify a cache key.
      Returns:
      This instance with the objects added.
      Throws:
      IllegalArgumentException - If any of the given objects is null.
    • append

      @Nonnull public CacheKey append(@Nonnull Object... objects)
      Appends the given Objects to this instance. In order to compare cache keys, Object.equals(Object) and Object.hashCode() are used. The given objects must not be null.
      Parameters:
      objects - Additional objects that should be used to identify a cache key.
      Returns:
      This instance with the objects added.
      Throws:
      IllegalArgumentException - If any of the given objects is null.
    • of

      @Nonnull public static CacheKey of(@Nullable Tenant tenant, @Nullable Principal principal)
      Constructs a CacheKey for the given tenant and principal identifier, independent of whether they are null or not. This provides the highest flexibility for defining different levels of isolation.
      Parameters:
      tenant - The tenant. If null, there is no tenant isolation.
      principal - The principal. If null, there is no principal isolation.
      Returns:
      A new CacheKey constructed from the given tenant and principal identifier.
    • fromIds

      @Beta @Nonnull public static CacheKey fromIds(@Nullable String tenantId, @Nullable String principalId)
      Constructs a new CacheKey instance for the given tenantId and principalId, independent of whether they are null or not. This provides the highest flexibility for defining different levels of isolation.
      Parameters:
      tenantId - The tenant identifier. If null, there is no tenant isolation.
      principalId - The principal identifier. If null, there is no principal isolation.
      Returns:
      A new CacheKey constructed from the given tenant and principal identifier.
      Since:
      4.6.0
    • ofNoIsolation

      @Nonnull public static CacheKey ofNoIsolation()
      Constructs an instance of CacheKey without tenant or principal isolation. This can be used to share a cache globally within the application.
      Returns:
      A new CacheKey without isolation.
    • ofTenantIsolation

      @Nonnull public static CacheKey ofTenantIsolation() throws TenantAccessException
      Constructs a tenant-isolated instance of CacheKey. This can be used to share a cache among the principals of a tenant.

      When using this method, the tenant isolation is strictly enforced. This means that if the tenant is not available, an exception is thrown.

      Returns:
      A new CacheKey with tenant isolation based on the current tenant.
      Throws:
      TenantAccessException - If there is an issue while accessing the tenant.
    • ofTenantOptionalIsolation

      @Nonnull public static CacheKey ofTenantOptionalIsolation()
      Constructs a tenant-optional-isolated instance of CacheKey. This can be used to share a cache among the principals of a tenant.

      When using this method, the tenant isolation is not enforced. This means that if the tenant is not available, an no isolation will be applied.

      Returns:
      A new CacheKey with tenant-optional isolation based on the current tenant.
    • ofTenantAndPrincipalIsolation

      @Nonnull public static CacheKey ofTenantAndPrincipalIsolation() throws TenantAccessException, PrincipalAccessException
      Constructs a tenant- and principal-isolated instance of CacheKey.

      When using this method, the tenant and principal isolation is strictly enforced. This means that if the tenant is not available or the principal is not authenticated, an exception is thrown.

      Returns:
      A new CacheKey with tenant and principal isolation based on the current tenant and principal.
      Throws:
      TenantAccessException - If there is an issue while accessing the tenant.
      PrincipalAccessException - If there is an issue while accessing the principal.
    • ofTenantAndPrincipalOptionalIsolation

      @Nonnull public static CacheKey ofTenantAndPrincipalOptionalIsolation()
      Constructs a tenant- and principal-optional-isolated instance of CacheKey.

      When using this method, the tenant and principal isolation is not enforced. This means that if the tenant is not available or the principal is not authenticated, the missing information is not used for isolation.

      Returns:
      A new CacheKey with tenant- and principal-optional isolation based on the current tenant and principal.
    • equals

      public boolean equals(@Nullable Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      @Nonnull public String toString()
      Overrides:
      toString in class Object
    • getComponents

      public List<Object> getComponents()
      Description copied from interface: GenericCacheKey
      Getter for the list of additional cache key components.
      Specified by:
      getComponents in interface GenericCacheKey<CacheKey,Object>
      Returns:
      The list of additional cache key components.