dresel / methodcache Goto Github PK
View Code? Open in Web Editor NEWA method and property caching Fody addin.
A method and property caching Fody addin.
It's a pity the last package does not work in Xamarin PCL projects (.net profile78). Annotation is not recognized.
Do you have some glue to let it work ?
@Dresel you might want to add a sample to here https://github.com/Fody/FodyAddinSamples/
Can u send me a pull request?
Instead bundle the readme with your lib:
<file src="readme.txt" target="" />
This will automatically display the file during installation.
Can redis be supported?
I've just found out that the [Cache] attribute is not removed from a class, when there was no methods found for rewriting.
In my example I wanted to add caching to a class which has only properties and because no method was found, the attribute wasn't removed.
Fody Version 2 is out and you will need to do an update for your addin to be usable with it
Specifically:
Please ping me if u need help
Example:
public T[] GetAll<T>();
Should be something like:
public override T[] GetAll<T>()
{
string text = string.Format("NAMESPACE.CLASS.GetAll_{0}", new object[]
{
typeof (T)
});
// ...
}
Hello,
Cache-key don't support array values :
Example :
public object[] TestMethod(object[] parameters)
{
return parameters;
}
The result is the same whatever the values contained in the array :
CollectionAssert.AreNotEquivalent(classTest.Method3(new object[] { 1, 2 }), classTest.Method3(new object[] { 2, 1 }));
=> The result is always object[] { 1, 2 }
Best regards,
If I try to run this on a class that contains an auto-generated read-only property (ie. no setter), it fails with an uncaught exception. The problem appears to be in the file MethodCache.Fody/ModuleWeaver.cs line 438:
bool hasSetAccessor = property.GetMethod != null;
Should be:
bool hasSetAccessor = property.SetMethod != null;
I notice you do an assembly scan to lookup CacheAttribute (for example). This is not required and will actually negatively impact the performance of you weaver.
Instead just scan the attributes of a method and do a string match on the attribute type name for "CacheAttribute"
This code crashes with Unhandled Exception: System.InvalidOperationException: Could not execute the method because either the method itself or the containing type is not fully instantiated.
using MethodCache.Attributes;
using System.Collections.Generic;
namespace ReproduceBug
{
public class Bug<T>
{
[Cache]
public string Execute(T input)
{
return input.ToString();
}
public DictionaryCache Cache => new DictionaryCache();
}
public class DictionaryCache
{
private readonly Dictionary<string, object> _cache = new Dictionary<string, object>();
public void Remove(string key) => _cache.Remove(key);
public void Store(string key, object value) => _cache[key] = value;
public T Retrieve<T>(string key) => (T)_cache[key];
public bool Contains(string key) => _cache.ContainsKey(key);
}
class Program
{
static void Main(string[] args)
{
var bug = new Bug<int>();
bug.Execute(0);
}
}
}
Mind upgrading ur FodyHelpers to >= 3.0.0?
Getting this with ur latest Alpha1:
Fody: The weaver assembly 'MethodCache.Fody, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null' references an out of date version of Mono.Cecil.dll. Expected strong name token of '1C-A0-91-87-7D-12-CA-03' but got '50-CE-BF-1C-CE-B9-D0-5E'. The weaver needs to update to at least version 3.0 of FodyHelpers.
Or any alternatives for it?
Why static method caching is not supported ?
If it is please tell me how can I do it.
Hi as I mentioned in issue #5 I have just discovered the it is not possible cache properties.
I suppose that is due to the fact the they combine both read and write methods so that that it is difficult to determine when to invalidate a cache key. However there is no guarantee that a method's return would not change due to some side effects of another method and in such situation the cache would indeed return stale data just as well.
Given the above I think it's worth extending MethodCache with support for properties in two steps:
I think I sould be able to help with step 1...
What do you think?
Hello,
When using MethodCache on a 3.5 assembly, a reference to mscorlib 4.0 seems to be added to the assembly.
If the debug messages are enabled, a reference to System 4.0 is added too, and I get a FileNotFoundException saying that System 4.0 can't be found.
I'm not sure if older versions of .NET are supported or not, so maybe it is just a matter of indicating it in the readme.
Best regards.
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.