Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Caching / January 2004

Tip: Looking for answers? Try searching our database.

cache location

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gsnke - 03 Jan 2004 16:56 GMT
So far I've been unable to find an answer to this question:

Is it possible to force cached content to be written to the disk in addition
to be kept in memory?

Here is what I'm trying to do:

We have about 100,000 images (e-commerce) to handle. The app will create
100px, 250px, 400px, etc - size images. That all works very well, except
that it doesn't sound feasible to have the Cache keep all that in memory.

So, I'm trying to determine how to write those altered images (altered via
querystring) onto the disk while still linked to the cache. I could think of
several ways to accomplish a home-cooked cache application, but I'd like to
concentrate on the .NET Cache object for this question.

Here's my ideal solution:

- inside the app all I'm doing is checking against the cache whether an
image exists or not and re-create depending on the result
- if an item does NOT exist, I will create one and write it into the cache.
- the cache will store it in memory AND write it onto disk.
- now, if the object gets purged out of memory next time I request that
image the cache could immediately go back to the disk and grab the object
from there without me having to go through the expensive creation process.
- the biggest thing is that this way I could still use all of the
dependencies that are so handy!!

Any ideas?
Alvin Bruney - 04 Jan 2004 00:30 GMT
You need a couple of steps here. You would need a cache call back delegate.
This allows you to repopulate the cache when the runtime removes items from
the cache. When this happens, your call back function triggers and you would
then be responsible for repopulating the cache with the item from disk.

You will need to enhance your logic (wrapping the cache object in a class
for instance) so that cache accesses check the cache object first and on a
miss, goes searching for the item on disk. Finding the item on disk
replenishes the cache and returns the info at the same time.

You can either overload the add and insert methods of the cache object or
provide your own wrapper class. It's up to you.

//code provided complements MSDN

static bool itemRemoved = false;
   static CacheItemRemovedReason reason;
   CacheItemRemovedCallback onRemove = null;

   public void RemovedCallback(String k, Object v, CacheItemRemovedReason
r){
     itemRemoved = true;
     reason = r;
   }

   public void AddItemToCache(Object sender, EventArgs e) {
       itemRemoved = false;

       onRemove = new CacheItemRemovedCallback(this.RemovedCallback);

       if (Cache["Key1"] == null)
         Cache.Add("Key1", "Value 1", null, DateTime.Now.AddSeconds(60),
TimeSpan.Zero, CacheItemPriority.High, onRemove);
   }

   public void RemoveItemFromCache(Object sender, EventArgs e) {
       if(Cache["Key1"] != null)
         Cache.Remove("Key1");
   }
//code complements MSDN

Signature

Regards,
Alvin Bruney
Got tidbits? Get it here...
http://tinyurl.com/2bz4t

> So far I've been unable to find an answer to this question:
>
[quoted text clipped - 25 lines]
>
> Any ideas?

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.