Purpose and Overview
This class allows for the creation of a global $SWP_Post_Caches object. This will be called and instantiated from the main loader class Social_Warfare. It will then be available to classes like the buttons_panel class which can then use it to fetch share counts for specific posts via their post_cache objects.
The purpose of this class is exclusively to create instantiations of the
SWP_Post_Cache class. That class creates cache objects for individual posts that contain cached data like share counts.
The reason we access that class via this class is to avoid multiple instantiations of post cache objects. When accessed via this class, it will check if a cache object has already been created. If so, it returns the one that already exists. If not, it creates one, saves it for future requests, and then returns it.
Usage
To access the cached share counts, it’s as simple as this:
$shares = $SWP_Post_Caches->get_post_cache( $post_id )->get_shares();
Be sure to check out the SWP_Post_Cache documentation for further information about the data that is created and returned.