-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: Utilizing ASP.net 2.0 advanced cache features
PostPosted: Sun Jan 01, 2006 11:29 am 
Newbie

Joined: Thu Dec 22, 2005 6:56 pm
Posts: 8
Hi all.

I was wondering if there is any common practice as to utilizing ASP.Net 2.0's application cache features such as SQL dependency cache in the NH second-level cache?

For instance, assume we have a persistant collection of items loaded from DB. I'd like to be able to store them in a second-level (shared) cache, and have the collection deleted from the cache when the underlaying table is changed.

Although ASP.Net 2.0 application cache supports this, I'm wondering if there is a way to get NH's second-level cache to utilize this feature?

Thanks in advance,
- Avi


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 03, 2006 11:33 am 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
I haven't dug into the new 2.0 features yet, as I'm on a WinForms project at the moment. Feel free to make feature requests in our Jira issue tracking system, so that I don't forget. ;)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 03, 2006 2:44 pm 
Newbie

Joined: Thu Dec 22, 2005 6:56 pm
Posts: 8
Quote:
Feel free to make feature requests in our Jira issue tracking system, so that I don't forget. ;)


Great, I'll post it in the JIRA. I just wasn't sure if the feature was already available or not..

p.s. what about other ASP.Net cache features such as cache-dependencies? I'm not sure how the current (sysCache) implementation works as far as dependencies go.. If an item is thrown out of the cache, do other dependant items get thrown out as well, or maybe this kind of dependancy isn't at all appliccable to NH's cached entities?

Thanks,
- Avi


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 03, 2006 8:12 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
I believe dependencies are not related - they are tied to files.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 04, 2006 2:59 am 
Newbie

Joined: Thu Dec 22, 2005 6:56 pm
Posts: 8
k-dub wrote:
I believe dependencies are not related - they are tied to files.


?? I dodn't think I understand.. you mean in NH or in ASP.Net cache?
In the ASP.Net cache, you can tie up a cached item to just about any kind of dependency - it can depend on an amount of time passing, on a file changing, on a table in the DB changing or even on another cached item.

Here's a nice overview of what is available and how to use it:
http://www.devx.com/dotnet/Article/27865/0/page/4

Anyway I entered the SQL Dependency issue in JIRA - that was my first post into the JIRA so I hope I got it right..

- Avi


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 04, 2006 10:44 am 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
Sorry for not being clear. What I meant was that when using a CacheDependency object to insert some object into an ASP.NET Cache, you can only depend on files. I don't see any way to depend on other cached objects or SQL code or anything else.

The Cache 2.0 API showing how to add items to the cache:
Code:
public object Add(string key, object value, CacheDependency dependencies,
    DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority,
    CacheItemRemovedCallback onRemoveCallback);
public void Insert(string key, object value);
public void Insert(string key, object value, CacheDependency dependencies);
public void Insert(string key, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration);
public void Insert(string key, object value, CacheDependency dependencies, DateTime absoluteExpiration,
    TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback onRemoveCallback);


The CacheDependency 2.0 constructors:
Code:
public CacheDependency(string filename);
public CacheDependency(string[] filenames);
public CacheDependency(string filename, DateTime start);
public CacheDependency(string[] filenames, DateTime start);
public CacheDependency(string[] filenames, string[] cachekeys);
public CacheDependency(string[] filenames, string[] cachekeys, DateTime start);
public CacheDependency(string[] filenames, string[] cachekeys, CacheDependency dependency);
public CacheDependency(string[] filenames, string[] cachekeys, CacheDependency dependency, DateTime start);


So the only way to get a dependency is to use the CacheDependency object, and the only way to use a CacheDependency is to specify a file name.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 04, 2006 5:47 pm 
Newbie

Joined: Thu Dec 22, 2005 6:56 pm
Posts: 8
Yes, except that any of the constructor's params can be NULL, so it doesn't have to depend on files ;-)

See the following code sample from MSDN that shows how to have one cached item depend on another. Notice that null is passed as the "filename" paramater to both CacheDependency's constructors.

Also notice how a daisychain of dependencies can be set up (in this example, Cache["key2"] depends on dep2, which depends on dep1, which depends on Cache["key1"].

Code:
public void CreateDependency(Object sender, EventArgs e) {
    // Create a cache entry.
    Cache["key1"] = "Value 1";

    // Make key2 dependent on key1.
    String[] dependencyKey = new String[1];
    dependencyKey[0] = "key1";
    CacheDependency dep1 = new CacheDependency(null, dependencyKey);

    // Make a second CacheDependency dependent on dep1.       
    CacheDependency dep2 = new CacheDependency(null, null, dep1);

    Cache.Insert("key2", "Value 2", dep2);

    DisplayValues();
}


So given this, do you think that NH can benefit from this kind of cache dependancy?

One example that comes to mind is having a collection invalidated from the cache once one of it's items is invalidated from the cache, but I'm not quite farmiliar with the inner workings of NH's cache, and maybe this is already handled in NH.

- Avi

p.s. should we be having this conversation in the JIRA or is ot OK to clutter the forum with this?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.