Add option to cache results

Created on 14 June 2022, over 2 years ago
Updated 20 August 2024, 3 months ago

Problem/Motivation

At times, searches may be repeated several times (for instance when updating content across many nodes). For larger search results, it may be useful to cache the results.

1) if this is added, there should be an option to enable or disable it, and possibly set the cache duration
2) If results are cached, the results set won't accurately reflect the true state of the content, and there needs to be a way to wipe the cache and force a new search

โœจ Feature request
Status

Fixed

Version

1.0

Component

Code

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States cskeers

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia souvik_banerjee

    Hi, I have added code to cache the results stored in table.

  • Status changed to Needs review about 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States themarkahrens

    mytungsten โ†’ made their first commit to this issueโ€™s fork.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States cskeers

    As is, the code

        $cache_key = 'search_results:' . md5(serialize($results));
        if ($cache = $this->cacheManager->get($cache_key)) {
          return $cache->data;
        }
    

    caches the full results set as part of the key, meaning the entire search process needs to run prior to fetching this cached data.

    The cache check/retrieval/set should likely surround the call to search_fields in searchButton and be keyed to the search parameters in order to bypass the full search process if cached data is present.

    Additionally, we'll need to at least have a configurable option to cache or not, and ideally, options to set number of cached entries and/or cache duration. These latter can be incremental improvements, but there needs to be the option to disable caching at the least.

  • First commit to issue fork.
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia manish-31

    Hi @cskeers,

    I have done the required changes please review and provide feedback to let me know if we need to improve the approach.

    Please find the changes/implementation below -

    • Added an option to enable/disable caching from settings form.
    • Added an option to set cache duration (in seconds), visible only when cache enable checkbox is checked.
    • Added a new checkbox field in the Search Form "Invalidate cache", if checked it will invalidate search results cache first and perform new search. Visible only if caching is enabled.
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia manish-31

    Attaching screenshots for reference -

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States themarkahrens

    This is now on the 1.x develop release for folks to start reviewing.

  • Status changed to RTBC 5 months ago
  • gaurav gupta Jaipur, Rajasthsan

    Hello @mytungsten @manish-31
    I have reviewed the MR and it is working as expected.
    When enabling invalidate cache it is taking more time in comparison to when disable it.

  • Status changed to Fixed 3 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States themarkahrens

    Published in the 2.0.4 release

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024