cache and objectdatasource

T

Trapulo

Hello,
I have a gridview that loads data from an objectdatasource. I want enable a
sliding cache on objectdatasource, but I need to cache data only when one
select parameter has a specific value (my select method requires 5
parameters, and I want use cache only when one parameter has a specific
value, to avoid consuming large amount of memory caching a lot of parameter
sets).

Is there any way to have this goal?

thanks
 
S

Steven Cheng[MSFT]

Hi Trapulo,

How are you doing?

For the ObjectDataSource caching question you mentioned, are you using the
default cache feature of the ObjectDataSource? If so, this cache feature is
done by the ObjectDataSource internally and will use the query method's
name and parameter colleciton as cachedKey. So far I haven't found any
interface for us to manually disable/enable this cache depend on some
certain query parameters. However, you can manually remove the cache of the
ObjectDataSource through the ObjectDataSource.CacheKeyDependency property.
See the following article:

#ObjectDataSource in Depth (Part 3)
http://www.manuelabadia.com/blog/PermaLink,guid,eaa3eed8-f997-43c4-8c30-78c2
f72d0c86.aspx

If you do need the capability of control the caching(of underlying data
record set) behavior, I may consider programmatically use ASP.NET Cache
object to cache the data in your data access class instead of
ObjectDataSource's cache support.

How do you tihnk?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 
T

Trapulo

Hi Steven,
I'm using default ObjectDataSource cache feature. My "select" method has
some parameters defined, and most queries will use a small set of values
(setting most of parameters to nothing), so I want cache their results to
avoid most of round trip to database. I think that "cachedKey" property is
not a solution, because it will clear all cache results and I need to
selective use Cache, but when I don't use it for a single query I want that
it remains in memory for the next.

I thinks the best way is to use ASP.NET Cache object from ObjectDataSource:
do you have any good reference you can suggest, to make a good
implementation of this?

Thanks
 
S

Steven Cheng[MSFT]

Thanks for your reply Trapulo,

I haven't any definite reference on how to creating such class since it is
more specific to data access component class development. I have ever
discussed some similar questions in the newsgroup and you can search for my
threads with some keywords like "objectdatasource", "Dataset"...

http://groups.google.com/group/microsoft.public.dotnet.framework.aspnet/brow
se_thread/thread/9ab375efebcf4c63/c433a129b8d87a7e

http://groups.google.com/group/microsoft.public.dotnet.framework.aspnet/brow
se_thread/thread/50824bfd534fa636/8ccee6bbf472c3a1

A common approach is let your data access class(used in objectdatasource)
always check the cache(with a generated key) and if cache not exists,
initialize the cache and then return the cached object(as return value of
your select method...). Also, you can programmtically specify the cache
dependency type(such as file dependency or sql database dependency)

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
T

Trapulo

Thank you Steven,
I've implemented a custom logic in my select method, and I'm using Cache
Object with a code like this:

Dim cacheKey As String, cacheCountKey As String
If [eval if may use cache] Then

cacheKey = [values] & "-"c & startRowIndex.ToString & "-" &
maximumRows.ToString

cacheCountKey = [values] & "-"c

If HttpContext.Current.Cache.Item(cacheKey) IsNot Nothing Then

Return DirectCast(HttpContext.Current.Cache.Item(cacheKey), Data.DataSet)

End If



[... retrieve data...]



If Not String.IsNullOrEmpty(cacheKey) Then

HttpContext.Current.Cache.Add(cacheKey, out, Nothing,
Now.AddMinutes(_cacheDurationMinutes), Nothing, CacheItemPriority.Low,
Nothing)

HttpContext.Current.Cache.Add(cacheCountKey, filter.TotalRows, Nothing,
Now.AddMinutes(_cacheDurationMinutes), Nothing, CacheItemPriority.Low,
Nothing)

End If

End If


thanks
 
S

Steven Cheng[MSFT]

Thanks for your followup.

Glad to be of assistance :)

Sincerely,

Steven Cheng
Microsoft MSDN Online Support Lead
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top