Caching

Estimated reading: 2 minutes 855 views

Leaderboard Caching

When generating leaderboards, especially where there are a lot of users or a lot of transactions, the leaderboard query can become resource heavy. You would mainly see this in the form of the leaderboard page taking a long time to load.

 

To cut down on unnecessary queries, the plugin caches the leaderboard results. This is done by saving the raw leaderboard result as a group meta value. This also includes a users position in each leaderboard. Instead of running a new query on each page load, their position is saved and only re-queried when needed.

Clearing the Cache

A groups leaderboard cache will be cleared automatically in the following situations:

  • A user joins or leaves the group.
  • A group member gains or loses points (depending on the leaderboard type used).
  • The leaderboard plugin settings are saved.
  • An admin saves the leaderboard setup in the group admin area.
  • A custom point type that has previously been used for leaderboards is deleted.

Caching Issues

There are a few scenarios where caching might cause some “issues”. If a leaderboard is based on a timeframe like today, this week or this month, the leaderboard cache will not be cleared at the end of each period. Instead it is cleared first when a member gains or loses points.

 

As an example, lets say we show todays point gains in our leaderboards and it is a new day. Throughout this new day, the leaderboard will show yesterdays results until someone in my group gains or loses points or any of the other above mentioned triggers occur.