best way to cache page statistics for link sharing from external sites?

i have added the ability to view sharing statistics form external social networks to my interconnected sharing plugin. so i can now show how many 'likes' and 'shares' each page has received via other social networks. this works fine, but i would like to cache the data so that page loads are not slowed down significantly. since the sharing buttons appear on some pages that do no represent unique elgg entities, such as main listing pages for blogs/files/pages etc. - i need a way to cache the counts of likes/shares from external sites that does not rely on elgg annotations.

what would be an easy and efficient way to do this in elgg? would creating a new form of elgg object to store the data be a good option? or is there another way?

thanks

  • I assume all these "pages" are entities?

    We do preload all metadata for fetched entities in one query. That means means asking for several pieces of MD won't cost additional queries, but each additional piece of MD adds a teensy bit of memory each time that entity is fetched whether the MD is needed or not.

    There are lots of oddball cases where I don't hesitate to add a custom table to add better control of indexing and joins. If you join another table via elgg_get_entities() you can still get at the extra selected rows using $entity->getVolatileData("select:my_column").

    Probably the simplest solution is to wrap a per-entity cache around that data. If it needs to be fast for every request no matter what, do the calculations and rebuild the cache in cron.

     

  • Oh, I missed the part about non-entities. A custom table is probably your best bet. You'll also need a way to canonicalize the URLs() to remove querystrings, fragments, etc.

  • ok thanks - i've got the table created and i'll maybe finish the rest today.

  • after some playing with the code, this feature is now working well - thanks for assisting!

  • Another option is to get the social statistics using ajax option. This way it will not interfere with page loading.

  • yes, i have already added ajax to the process - with the server caching also in place to reduce loads. it works great.