Get config value every time or store as value in class

Discussion in 'Plugin Development' started by Dai_Kunai, Mar 28, 2022.

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

    Dai_Kunai

    So, is it okay to check the config's value every time (for an event that happens a lot), or should I save these values in the beginning in my class to some field variable. I'm not reloading the config or anything, so I think it's okay to getConfig().getBoolean(...) every time but I'm not 100% sure. I'm assuming loading the config every time would not be as okay.

    Thanks,
    DaiKunai
     
  2. Offline

    Strahan

    Yep, that's fine. Reading is not a problem as the server caches the config after the first read. Writing is what is resource expensive, as it involves disk I/O each time you call saveConfig()

    PS as you said, reloading from disk is also expensive. I was originally referring to the built in config.yml. If you are using your own config, just read it into a memory cache onEnable then you can read from the cache with no impact. It's just the initial read that hits the server harder.
     
  3. Offline

    Dai_Kunai

    I currently have a custom one where I load it in the beginning, is that okay? I only save into that onDisable
     
  4. Online

    timtower Administrator Administrator Moderator

    That is absolutely fine.
    My configs work the same way.
     
Thread Status:
Not open for further replies.

Share This Page