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

Implement cache for object queries #127

Open
Rahe opened this issue Apr 11, 2022 · 1 comment
Open

Implement cache for object queries #127

Rahe opened this issue Apr 11, 2022 · 1 comment

Comments

@Rahe
Copy link
Member

Rahe commented Apr 11, 2022

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.

@Rahe Rahe changed the title Implement cache for current_object_is_synchronized Implement cache for object queries Apr 11, 2022
@Rahe
Copy link
Member Author

Rahe commented Apr 11, 2022

By the way, we need to store that there is no relation into the cache with a false value and not forget to clear cache on relation creation after this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants