Make WordPress Core

Opened 16 years ago

Closed 16 years ago

Last modified 10 years ago

#10274 closed defect (bug) (worksforme)

Simplify options caching

Reported by: ryan's profile ryan Owned by: ryan's profile ryan
Milestone: Priority: low
Severity: minor Version:
Component: Cache API Keywords:
Focuses: Cc:

Description (last modified by ryan)

Instead of caching all options and their values to a big array, let's cache only the option names to an array and cache the values individually. The option name cache will be passed to wp_cache_get_multi() (which needs to be added) at startup to prime the option cache. Here's the flow.

(List of option names cached to all_options)

First page load:

  • wp_cache_get all_options
  • Nothing is cached to all_options, so query db for all option names and values
  • Loop over DB results, wp_cache_add each option and construct all_options list.
  • wp_cache_set all_options with the options list * Cache for each option is now primed via the wp_cache_adds.

Next page load:

  • wp_get_get all_options
  • all_options has cached list of option names, pass those names to wp_cache_get_multi
  • get_multi does one memcached request for all options
  • cache is now primed for all options, each option in its own bucket, no need to query DB

Attachments (1)

10274.diff (9.7 KB) - added by ryan 16 years ago.
Untested and incomplete and possibly crackheaded

Download all attachments as: .zip

Change History (7)

@ryan
16 years ago

Untested and incomplete and possibly crackheaded

#1 @ryan
16 years ago

The notoptions cache is not really dealt with yet. On wp.com and some other WPMU setups, all options are autoloaded so you can assume that if an option isn't present after all options are loaded it does not exist. There's no need for a separate notoptions cache. We can't do that on WP. The query in that patch makes the assumption that all options are autoloaded, so that will have to change. The patch and this ticket are simply meant to get discussion flowing.

#2 @ryan
16 years ago

  • Description modified (diff)

#3 @ryan
16 years ago

wp_cache_get_multi() is important for cache backends like memcached. Requesting options in one go rather than in dozens of individual requests performs much better.

#4 @hailin
16 years ago

I think it's a good idea to retain notoptions cache, because the presence of all option names cache does not guarantee the presence of every individual option (the former one could expire or been deleted earlier). Besides, there is no easy way to check get_multi returns all individual options. It just returns a big array.
Keeping notoptions cache makes the logic complete and safe.

#5 @hailin
16 years ago

  • Priority changed from normal to low
  • Resolution set to worksforme
  • Severity changed from normal to minor
  • Status changed from new to closed

Further investigation indicates that current cache by alloptions seems to be working just as well. Previous bugs were caused rather by other aspects of caching hierarchy.

#6 @DrewAPicture
10 years ago

  • Milestone 2.9 deleted
Note: See TracTickets for help on using tickets.