Skip to content

Implement cache for object queries #127

@Rahe

Description

@Rahe

Hello,

If the method current_object_is_synchronized is called 3 times in a row in the same page, we make 3 database calls.
The elements doesn't change between such page load, and until the elements is deleted from the database relations or changed, the data doesn't expire.

This problem is particulary proheminent on attachment listing pages, the methods can be called from 2 to 10 times for each image depending on the number of image sizes.

I think this is a great idea to add a cache layer on theses calls.
The best way to handle this is to use the wp_cache API (wp_cache_get/wp_cache_set) and use a group for theses.

The implementation need to

  • Handle get_object_id_for_receiver that generate a cache key like from_receiver:{types}{receiver_id}:{receiver_line_id}
  • Handle get_object_id_for_emitter that generates a cache key like from_emitter:{types}{emitter_id}:{emitter_line_id}
  • Handle current_object_is_synchronized that generates a cache key like from_receiver:{types}{receiver_id}:{receiver_line_id}
  • Have a global group into the object since the ressources can be called from anywhere into a multisite and doesn't change wp_cache_add_global_groups
  • Have a method that allows us to pass a row from the relation table, and clear all possibly generated keys from cache for the resource, with the whole line we can regenerate the keys generated from all the other methods

Theses are the mainly used methods into the code.
I think a method to generate the cache keys from the entries (from_emitter and from_receiver) will be usefull for this.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions