0
我正在爲我的應用程序開發一個簡單的緩存類。C#與代表緩存
using System;
namespace Program {
public class Cache {
public delegate int CacheMethodInt();
public static int Get(CacheMethodInt method) {
//todo: generate cachekey here
return method.Invoke();
}
}
public class Calculator {
public int Add(int x, int y) {
return x + y;
}
}
class Program {
static void Main(string[] args) {
Calculator c = new Calculator();
Console.WriteLine(Cache.Get(() => c.Add(1, 2)));
}
}
}
在Cache:Get
我需要檢查返回值是否已經被緩存,如果沒有調用該方法,從而返回。問題是我無法弄清楚如何生成一個好的緩存鍵。在這種情況下,我想是這樣的:
是否有可能獲得Cache:Get
這個信息?我正在使用.NET 2.0。
這是沒有意義的緩存數據,它是此便宜重新計算。使用[家庭作業]標籤作家庭作業問題。 – 2012-07-19 17:06:20