Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache indexables when they are retrieved #19555

Open
BobBreukhoven opened this issue Jan 6, 2023 · 0 comments · May be fixed by #19121
Open

Cache indexables when they are retrieved #19555

BobBreukhoven opened this issue Jan 6, 2023 · 0 comments · May be fixed by #19121
Assignees

Comments

@BobBreukhoven
Copy link
Contributor

BobBreukhoven commented Jan 6, 2023

https://yoast.atlassian.net/browse/DUPP-627

Whenever a page is visited on the frontend, we query the database for its accompanying indexable. We do not cache this indexable, leading to repeating database queries when revisiting or reloading the page (even though the indexable tied to that page would most likely not have changed in the mean time).

We do cache the indexable within a page load (within the Meta_Tags_Context_Memoizer), to reduce the amount of database queries within a page load. However, we do not have any caching behavior between page loads.

Accompanying issue on GitHub: Uncached SQL queries on every page load. WAIT FOR FEEDBACK

Possible approach

We could add caching behavior between page loads within the Meta_Tags_Context_Memoizer, or possibly within the Indexable_Repository, most likely using the WordPress caching functions.

Whenever an indexable is rebuilt, we can invalidate the cached value for that indexable again. This could be done in the Indexable_Builder class, since it is the main entry point for (re)building indexables.

Notes

  • Adding caching, without proper invalidation, carries risk. If the cached indexable is inconsistent with the indexable stored in the indexables table we could output the wrong information on the frontend for that indexable. This can have serious SEO impact. We have to make sure that the cache is invalidated every time the indexable is changed.
  • We should take performance into account. More specifically the balance between having potentially lots of cached indexables (one for each page on a site) and the cost of re-querying the database for an indexable on each page load.
    • Note that the queries try to retrieve a handful of indexables per page, which should be fast given the indexes on the indexables table.
      • Most of the times this is the indexable for the page itself, and one or more extra indexables to be able to generate the breadcrumbs.

Is duplicated by: https://yoast.atlassian.net/browse/DUPP-633

Ari started work on this: wordpress-seo: Add caching to queriesOPEN

@enricobattocchi enricobattocchi linked a pull request Feb 14, 2023 that will close this issue
13 tasks
@leonidasmi leonidasmi changed the title Cache indexables when they are retrieved using find_by_id_and_type Cache indexables when they are retrieved Apr 25, 2023
@leonidasmi leonidasmi self-assigned this Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants