Should I use wp_cache in my plugin to make it faster?
As a plugin developer, I strive for coding plugins that take as less server resources as possible. That's why I thought of avoiding to repeat queries to the database that are run on the same request (non-persitent).
Let's say my plugin has a function/class that needs to retrieve a setting from the options table (using the get_option
WP core function). And that I know that same value will be needed by another function/class that will be run sometime after (within the same request/page load).
My question is, what would be more efficient and faster:
A) Store the value in a PHP constant
B) Store the value in a PHP global variable
C) Pass the value between calling functions
D) Use WP_Cache
(cache it the first time I retrieve it and then check if a cached value exists before querying the database)
E) Do nothing and stop thinking. There's no real improvement.
OK, and what if instead of a single value, they were many, like an array of data? Would the appropriate answer be still the same? What if I'd had my settings stored in several keys and I'd like to retrieve all of them in the first place to stored them and avoid having to query/execute the get_option function as the code runs down?
Topic coding-standards php cache plugin-development Wordpress optimization
Category Web