Interface DtoCache

All Known Implementing Classes:
DtoCacheImpl, NoOpDtoCache

public sealed interface DtoCache permits NoOpDtoCache, DtoCacheImpl
The DtoCache interface defines methods for caching Data Transfer Objects (DTOs). It provides functionality for retrieving and storing DTOs using their class type and an identifier. Implementations of this interface can manage caching strategies for efficient reuse of DTO instances.

This interface has the following key methods:

  • get(Class, List): Retrieves a cached DTO of the specified class type and identifier, or null if no matching DTO is found in the cache.
  • put(List, Object): Stores a new DTO in the cache associated with the provided identifier.

The interface is designed as a sealed interface with two implementations:

  • NoOpDtoCache: A no-operation implementation that does not perform any actual caching.
  • DtoCacheImpl: A concrete implementation that uses a Map-based caching mechanism.
  • Method Summary

    Modifier and Type
    Method
    Description
    <DTO> @Nullable DTO
    get(Class<DTO> dtoClass, List<Object> id)
    Retrieves a cached Data Transfer Object (DTO) of the specified class type and identifier.
    <DTO> @Nullable List<DTO>
    getAll(Class<DTO> dtoClass)
    Retrieves a list of all cached Data Transfer Objects (DTOs) of the specified class type.
    void
    put(List<Object> id, @Nullable Object dto)
    Stores a Data Transfer Object (DTO) in the cache associated with the provided identifier.
  • Method Details

    • get

      <DTO> @Nullable DTO get(Class<DTO> dtoClass, List<Object> id)
      Retrieves a cached Data Transfer Object (DTO) of the specified class type and identifier. If no matching DTO is found in the cache, this method returns null.
      Type Parameters:
      DTO - The type of the Data Transfer Object.
      Parameters:
      dtoClass - The class type of the DTO to retrieve.
      id - The identifier used to locate the DTO in the cache. This is typically a list of keys representing a unique identifier for the DTO.
      Returns:
      The cached instance of the specified DTO type matching the given identifier, or null if no such DTO is found.
    • put

      void put(List<Object> id, @Nullable Object dto)
      Stores a Data Transfer Object (DTO) in the cache associated with the provided identifier. The identifier is typically a list of keys that uniquely represents the DTO. If the provided DTO is null, this method may effectively remove any existing entry associated with the given identifier, depending on the implementation.
      Parameters:
      id - The identifier used to associate the DTO with a cached entry. This is typically a list of keys representing a unique identifier for the DTO.
      dto - The Data Transfer Object to store in the cache. It can be null if the entry should be removed or not stored.
    • getAll

      <DTO> @Nullable List<DTO> getAll(Class<DTO> dtoClass)
      Retrieves a list of all cached Data Transfer Objects (DTOs) of the specified class type. If no DTOs of the given type are found, this method returns null.
      Type Parameters:
      DTO - The type of the Data Transfer Objects.
      Parameters:
      dtoClass - The class type of the DTOs to retrieve.
      Returns:
      A list of DTOs of the specified type currently in the cache, or null if no DTOs of the given class type are found.