0
votes

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?

1
How big of a datasource are we talking? 10 rows, 100 rows, 1000000 rows?CodingGorilla
Not huge, but I suppose my concern is overwriting cached or session'd objects.jlrolin
The reason I asked about size is you might consider putting the data in the viewstate, rather than server side caching (unless there are security concerns).CodingGorilla
Viewstate is an option as well.jlrolin

1 Answers

0
votes

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.