Giter Site home page Giter Site logo

Comments (2)

AlexScigalszky avatar AlexScigalszky commented on September 15, 2024

Maybe it's a good place to implement Memoization (I've never do that)..
Maybe something like this

public async Task<T> Get<T>(string path) 
    where T : new()
{
    VaultClient client = new VaultClient(new VaultClientSettings(_vaultSettings.VaultUrl,
        new TokenAuthMethodInfo(_vaultSettings.TokenApi)));

    var requestFn = async (string path) => await client.V1.Secrets.KeyValue.V2.ReadSecretAsync(path: path, mountPoint: "secret");

    Secret<SecretData> kv2Secret = await requestFn.ThreadSafeMemoize()(path);
    
    var returnedData = kv2Secret.Data.Data;
    return returnedData.ToObject<T>();
}
public static Func<A, R> ThreadSafeMemoize<A, R>(this Func<A, R> func)
{
    return Memoizer.ThreadSafeMemoize(func);
}
public static Func<A, R> ThreadSafeMemoize<A, R>(Func<A, R> func)
{
    var cache = new ConcurrentDictionary<A, R>();
    return argument => cache.GetOrAdd(argument, func);
}

Of course, with this approach it's impossible to implement retries and in case of an error, the error will be in the cache and it will be the result while the application is running. I don't know, it's just a good place to practice Memoization xD

from distribt.

ElectNewt avatar ElectNewt commented on September 15, 2024

@AlexScigalszky nah memoization is good when you have to query something and then query it again and again, etc and you konw it will never change. in this case the issue is different.

the idea on this task is to intercept somehow the failed queries by unauthorrized and do the getconnection call then retry with the new credentials, being completly transparent to the app.


A good place for memoization is in the MongoConnectionProvider :

the GetMongoUrl can be done with memoization

, at least until this task is implemented

from distribt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.