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

Optimization: cache queries and values for certain callback methods #152

Open
kimcoleman opened this issue Oct 31, 2023 · 1 comment
Open

Comments

@kimcoleman
Copy link
Member

Is your feature request related to a problem? Please describe.
To keep this plugin as optimized as possible, it would be useful to do a run through and cache some queries/methods.

We should update the call back methods in the modules to cache queries.

For example, https://github.com/strangerstudios/sitewide-sales/blob/dev/modules/ecommerce/pmpro/class-swsales-module-pmpro.php#L855-L892

From Jason: This could also be a good opportunity to go through the process with our dev team as the need comes up a fair bit.. There are a few different methods to caching (static vars, WP cache functions, transients), and each has its place.

Static vars best for cases where there is a single value that doesn't change throughout the course of the page load (may be the case here). Easiest, don't really need to invalidate the cache later.

WP get/set cache functions to potentially cache between page loads, or if you need to save values for different parameters (we sometimes still save in static vars and create a cache hash/key), and when invalidating/breaking the cache later is not complicated.

Transients are best for fully generated HTML snippets, should be saved between page loads, and is easy or at least possible to invalidate... or it's not so bad for it to be out of date.

Kim Coleman
1 hour ago
I’ll log the caching in the callback notes here as an issue.

@ideadude
Copy link
Member

ideadude commented Nov 1, 2023

In addition to some we need to cache, you can use the Query Monitor plugin and check the "duplicate queries" report to find queries that should be cached in SWS. Should browse around the admin and frontend pages and check the report for seeing queries in different contexts.

Screenshot 2023-11-01 at 5 43 59 PM

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

No branches or pull requests

2 participants