简体   繁体   中英

How to clear ObjectDataSource cache manually

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.

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.

In .aspx

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

In c#

Cache.Remove(ODSData.CacheKeyDependency);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM