Search Query and Result Caching

By default, the HDR FHIR server supports caching of search queries and their associated results in the database during search operations.

In HDR FHIR, the tables HFJ_SEARCH, HFJ_SEARCH_RESULT, and HFJ_SEARCH_INCLUDE are used to store and manage the results of FHIR search operations. These tables play a critical role in improving search performance, reusability of cached results, and pagination.

  • The HFJ_SEARCH table stores metadata about each search operation, including the search parameters and timestamps. If the same query is executed again and the cached result is still valid, it can be reused.
  • The HFJ_SEARCH_RESULT table stores references (by PID) to the resources that matched a specific search. These resource PIDs are used to deliver the search results.
  • The HFJ_SEARCH_INCLUDE table stores information related to _include and _revinclude search parameters. When a search includes related resources (e.g., Observation?subject=Patient/123&_include=Observation:subject), this table holds the additional resources that should be returned along with the primary results.

Search Cache Use Case

1. A user issues a search request to the HDR FHIR server.

2. The server checks if an identical search is already in HFJ_SEARCH and is still valid.

3. If cached, results from HFJ_SEARCH_RESULT (and HFJ_SEARCH_INCLUDE if applicable) are reused.

4. If not, the search is executed, and results are persisted in these tables for potential future reuse.

In HDR FHIR, the following properties control the behavior of search result caching, specifically how long search results are stored and whether they can be reused for subsequent queries:

Property Description
retain_cached_searches_mins This sets the retention period (in minutes) for cached search results in the database. The default value is 60.

Cached search results will be retained for 60 minutes after creation. After that, they may be cleaned up by the system using background scheduler job.

reuse_cached_search_results_millis This defines how long (in milliseconds) the cached search results are eligible for reuse. Default value is -1.

If it is set to a specific value in milliseconds, the cached results will be reused if an identical search is requested multiple times within this configured milliseconds.

If set to -1, search results are never reused, even if they are cached, so every search query will be executed fresh, even if the exact same query was run recently.

Disabling Caching

The HDR FHIR server can be configured to disable FHIR search queries and the associated result caching in the database using the following configuration property:

search_query_result_cache_enabled: false

  • If this property is set to false, the server will skip caching entries in the HFJ_SEARCH, HFJ_SEARCH_INCLUDE, and HFJ_SEARCH_RESULT tables during each FHIR search query execution.
  • If this property is not present, or if it is set to true, the server will cache search queries and their results in the respective tables by default.