gaweph / memoizer Goto Github PK
View Code? Open in Web Editor NEWEasy to use Memoize/Caching attribute implemented in C#
Easy to use Memoize/Caching attribute implemented in C#
Thanks!
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?
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.