iluwatar / java-design-patterns

Design patterns implemented in Java
https://java-design-patterns.com
Other
89.54k stars 26.47k forks source link

Caching Filter pattern #1266

Open iluwatar opened 4 years ago

iluwatar commented 4 years ago

Description: The Caching Filter design pattern aims to improve the performance and scalability of an application by caching the results of expensive operations and reusing them for identical subsequent requests. This pattern is particularly useful in scenarios where the same data is frequently requested, and the cost of recomputing the data is high.

Main Elements of the Pattern:

  1. Filter: Intercepts requests and checks if a cached response is available.
  2. Cache Store: A storage mechanism for saving and retrieving cached data.
  3. Cache Key: A unique identifier for caching entries based on request parameters.
  4. Expiration Policy: Defines how long cached data is considered valid.
  5. Cache Miss Handler: Fetches data from the original source when a cache miss occurs and populates the cache.

References:

Acceptance Criteria:

  1. Implement a basic Caching Filter that can intercept requests and check for cached responses.
  2. Develop a simple cache store with a configurable expiration policy.
  3. Ensure comprehensive unit tests are provided to validate the correct functionality of the caching mechanism.
KingOfXi commented 2 years ago

Well ,it's pretty interesting. I'd like to achieve it .

iluwatar commented 2 years ago

Ok @KingOfXi, go ahead