3

I am unable to find an answer to simple question: How to clear ObjectDataSource cache manually -- from my C# code. Using ASP.NET with .NET v4 in Visual Studio 2010 with some DevExpress components.

I have:

<asp:ObjectDataSource ID="SomeId" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="SomeMethod" TypeName="SomeType" EnableCaching="True" CacheDuration="9999" CacheExpirationPolicy="Absolute"> </asp:ObjectDataSource>

I have read the similar question: Where does the ObjectDataSource cache data? which links to: ObjectDataSource.EnableCaching Property. It says that cache is stored in the Cache object (Page.Cache).

All other advices I have found, leads to Cache object. The problem is: Cache is empty for me, and Cache.Remove(ObjectDataSourceID.CacheKeyDependency); does nothing.

The caching mechanism works even when Cache is empty. Changing EnableCaching to false disables cache, but after setting it to true, it enables cache back with cached old values.

Community
  • 1
  • 1
Maris B.
  • 2,333
  • 3
  • 21
  • 35
  • 1
    `ObjectDataSource` uses a private `SqlDataSourceCache` instance to store data. This private member is only exposed by an internal `Cache` property, so you won't be able to access it unless you break encapsulation through reflection. – Frédéric Hamidi Mar 02 '12 at 11:00

2 Answers2

3

Thanks to the Frédéric Hamidi comment, I found the following topic: Clear cache in SqlDataSource

Using CacheKeyDependency="MyCacheDependency" and then in the code:

Cache["MyCacheDependency"] = DateTime.Now; -- invalidates cache.
Community
  • 1
  • 1
Maris B.
  • 2,333
  • 3
  • 21
  • 35
1

In .aspx

<asp:ObjectDataSource ID="ODSData" runat="server" 
    EnableCaching="true" CacheKeyDependency="MyCacheKey"

In c#

Cache.Remove(ODSData.CacheKeyDependency);
spiderman
  • 1,565
  • 2
  • 16
  • 37