Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Aug 09, 2020 @ 21:44
    Alex Skrypnyk
    0

    Store value outside the application

    Hello Community

    I need to store some variables outside of the application lifecycle. So when application restarted I need to be able to access the value. This is actually just a number so I don't want to use a database.

    Does Umbraco have something to store such kind of data? I know that I can store on the IIS level or file, but still, maybe some helper available?

    Thanks, Alex

  • Anders Bjerner 487 posts 2989 karma points MVP 8x admin c-trib
    Aug 09, 2020 @ 22:46
    Anders Bjerner
    100

    This sounds like a scenario in which you could use IKeyValueService. It does save a row in the database, but otherwise it might be the "helper" you're looking for

    https://our.umbraco.com/apidocs/v8/csharp/api/Umbraco.Core.Services.IKeyValueService.html

    There isn't really any documentation besides the above reference documentation, but you can get an instance like:

    IKeyValueService kv = Current.Factory.GetInstance<IKeyValueService>();
    
    // Retrieve the "Hello" key from the database
    string value = kv.GetValue("Hello");
    
    // Set a value for the "Hello" key in the database
    kv.SetValue("Hello", "Some value");
    

    I don't know your specific use case, but having this in the database would generally be considered safer than having it in a file on disk.

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Aug 10, 2020 @ 22:34
    Alex Skrypnyk
    0

    Anders, thank you so much!!! I owe you a beer :) hopefully, next Codegarden!!!

Please Sign in or register to post replies

Write your reply to:

Draft