开发者

ASP.net: Gridview Datasource Caching Question

I currently have a control that called MyGridview that inherits Gridview. It has a paging template within it for customized paging options, and I'm at the point where I want to cache the initial datasource for better performance.

I haven't done this in a long time, so perhaps there is a different solution these days with the newer frameworks. Before, I simply used a Cache object that was named 开发者_运维问答whatever the gridview was named. I couldn't use the same gridview name through the application though.

Is there a best way to have a cache object, or some other object like a session within the control to store those unique datasets for paging and sorting?


Since you are talking a custom control, I would recommend abstracting it so whoever is using the application can define their own strategy. Define an interface:

public interface IGridCaching {
  object LoadCache();
  void SaveCache(object data);
}

Create a default implementation DefaultGridCaching and implement the solution you want, and expose it as a property of the Grid:

public IGridCaching Caching
{
    get { return this._caching ?? new DefaultGridCaching(); }
    set { this._caching = value; }
}

And then it becomes customizable. There haven't been a huge amount of changes; caching is still a good option. Using the Enterprise Library Caching block is another caching solution. But this way, caching is customizable.

HTH.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜