Cache a read only root list

Cache a read only root list

Old forum URL: forums.lhotka.net/forums/t/670.aspx


Michael Hildner posted on Wednesday, July 19, 2006

Hi,

I have a read only root list that I use for lookups. The list contains images, so it's kinda large and noticeably slow pulling across the network. The list rarely changes.

Is there anything wrong with changing my class so it's like a NameValueList? That is, have an instance variable of the same type as the class, and in the public static Get method, populate it if it's null, otherwise just re-use it?

Seems to me that would be ok, but I've made lots of mistakes due to ignorance, so I thought I'd ask.

Thanks,

Mike

Brian Criswell replied on Wednesday, July 19, 2006

There should be nothing wrong with that.  One thing you may want to think of is under which scenarios will the cache need to be invalidated.

RockfordLhotka replied on Wednesday, July 19, 2006

No, that is a fine thing to do. You can follow the pattern I used in RoleList to do the cache, and to provide a way to invalidate that cache if needed.

Michael Hildner replied on Wednesday, July 19, 2006

Brian and Rocky,

Thanks for verifying. I'll make an InvalidateCache() method that sets the instance variable to null in case it's ever needed. The list changes so infrequently (every couple months or so), I can probably get away with just re-launching the app.

Thanks,

Mike

david.wendelken replied on Thursday, July 20, 2006

I was skimming thru some new 2.0 features and recall reading that you can tie a cache to a data table, which means it would automatically invalidate when the table changes.

Sounds like what you might need!

Haven't tried it yet - so maybe it doesn't work or I mis-read that section. :)  I'm a couple of weeks away from trying that in my own project...

Michael Hildner replied on Thursday, July 20, 2006

Interesting, I don't recall reading that. Can you point me to a reference?

Thanks,

Mike

david.wendelken replied on Thursday, July 20, 2006

Professional ASP.NET 2.0, Evjen, et al.  Publisher: WROX (Wiley Publishing)

p. 752:

"Because of the unsealing of the CacheDependency class, the ASP.NET team has built a new SQL Server cache dependency -- SqlCacheDependency.  ...  When a cache becomes invalid because a table changes within the underlying SQL Server, you now know it immediately."

p. 756 and following describe the SqlCacheDepency usage.

Keep us posted on how it works!  (And any gotchas you run into.)

Michael Hildner replied on Thursday, July 20, 2006

Thanks David,

I'll have to read up on that. I'm working on a Windows Forms project right now, so not sure if I could use it, but it sounds cool.

Mike

Copyright (c) Marimer LLC