Giter Club home page Giter Club logo

memoizer's People

Contributors

gaweph avatar superjmn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

memoizer's Issues

Same method, different instance, same results

I have this test to illustrate the problem. I assumed calling the same method on a different class would give different results.

While this can be interesting in some scenarios, I consider that caching scope feel more natural in a per-class fashion.

public class MemoizerTests
{
    [Fact]
    public void Cached_method_in_different_instances_should_return_different_results()
    {
        var i1 = new MyClass("hello");
        var i2 = new MyClass("how are you?");

        var one = i1.Get();
        var two = i2.Get();
        Assert.NotEqual(one, two);
    }

    class MyClass
    {
        private string payload;

        public MyClass(string payload)
        {
            this.payload = payload;
        }

        [Cache]
        public string Get() => payload;
    }
}

Does it make sense to create an option in the CacheAttribute to choose the scope level?

  • per-type
  • per-instance

Does this work well with unit tests?

Python has had @cached decorator for a long time and I just tried it. Sadly, when running unit tests which send different values through cached functions, I learned that unit tests suites typically all share the same process, and in the case of python, the same "lifetime of the application". So basically, @cache makes a a function a singleton/global, which is a problem for unit tests (both parallel and sequential were affected).

Does that all apply to this library as well?

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.