Caching data.

Discussion in 'Plugin Development' started by WolfMage1, May 18, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    WolfMage1

    Say that I have a mass of data about each player

    Username, UUID, First Login, Server, Credits etc..., And this data isn't really modified often so instead of requesting data that doesn't change often I want to cache it when they join and access that cached data, how would I go about doing that?
     
  2. Offline

    DoggyCode™

    You could have a runnable periodically saving (runnable tasks) data such as that to a file or just save it a temporary way within the code (using hash maps and such).

    EDIT:
    But yeah, I would just listen to a join event, and save such information within the code, and later get it.
     
  3. Offline

    WolfMage1

    I know that, just.. what is an efficient way of caching it.
     
  4. Offline

    I Al Istannen

    @WolfMage1
    Well, many of the things you said are stored in the Player object, so you could store a reference to that. Just make sure to delete the reference if the player leaves. Caching is probably only useful, if the data is accessed often and you need high performance /low latency there. A simple way would be a HashMap, with a maximum number of entries and maybe decaying based on the last accessed time. This prevents the map from consuming too much memory, if you have bigger objects stored there. I have not much experience with caching systems, but there might be one in the Apache Commons lib bundled with bukkit. You could also try google-ing "java caching system", "java caching data" or similar. Can't help you further though, sorry.
     
  5. Offline

    WolfMage1

    sadly a lot of the data I store is not in the player object. But thanks for the help.

    EDIT: After doing a bit more surfing I managed to find this on JavaWorld

    http://www.javaworld.com/article/20...c-caching-service-to-improve-performance.html (for anyone else who's interested)
     
    Last edited: May 18, 2016
Thread Status:
Not open for further replies.

Share This Page