Sign In Register

How can we help you today?

Start a new topic

Cache leaderboard?


wre're using GameSparks for our game that's getting near to release date, so far so good: we're very happy with the service.

We have 2 leaderboards in our game, one is social (Facebook connected players) and one is global.

It works perfectly, but last night a question came to my mind about whether our "get global leaderboard" code had to be optmized or not.

I guess the answer is yes, but I'd like to know that do you think about it.

At the end of every game (about 1-2 mins) we make a request to GameSparks to get the global leaderboard.

This is what happens in our cloud code function:

- get first 25 entries of leaderboard

- obtain player data (from our "playerData" collection) of each entry player to get some info (photoId mainly)

- load playerInfo with "Spark.loadPlayer" api for each player to obtain its externalIds

- create a json array with the data, add a new entry for current player if he's not in the first 25 and return it

I guess I could optimize by retrieving externalIds only in case we're retrieving the social leaderboard, but anyway I'd like to know if I should cache this leaderboard structure in a collection and retrieve it when a player with rank > 25 asks for the global leaderboard.

If a player with rank < 25 asks for the global leaderboard then I recreate the json array and update it in the collection.

Obviously this can't happen in the case of social leaderboard because it's never the same.

What do you think about it?

Should I cache this data or am I over-thinking?

Thank you!


Hi Marco,

Apologies but I'm not quite sure what you're trying to achieve here, can you let me know the name of your game so I can go in and take a closer look ? Are your two Leaderboards feeding off the data from the same running total or are they populated by separate events ?



The name of the game is Waste in Space.

The event used to retrieve leaderboards is "GetLeaderboard" and I pass a parameter to select which kind of leaderboard I want.

In the game I have two leaderboards: one is social (Facebook friends) and the other is global (show the first 25 global best scores and the player rank and score), but they feed off from just one leaderboard named "ScoreLeaderboard".

I use:


to get the social leaderboard, and:


to get the global leaderboard.

Let me know if you need other information!



Login to post a comment