Project Description
Provides a scope to wrap around the velocity caching service. It also handles locks and unlocks so that if an item is called and should be locked after an initial call the scope can handle this under the covers.

Resolves the memory leak problem with cachefactory object.

This project resolves a memory leak issue with Velocity CTP2 and also provides a methodology for handling locked cached objects through a scope provider.

When you want to cache your objects you should wrap the commands in the cachescope using a using statement. This will then interact with the CachingService object to decide how to handle the locking and unlocking of objects.

In order to use locking you must use the scope or else it will not be possible to read an object once you have locked it. The other benefit is that when the scope is cleared all locked objects will be unlocked as a reference to each of them is held by the scope provider. This also means that if you have locked an object, you don't have to go back to the cache to get it but rather the scope can give it back to you right away. This is like having a local cache, only it's much closer to your code. When the scope is disposed, the objects are unlocked and released and memory is cleaned up.

You may also nest the caching scopes just like you would transactions in the sqlclient model. If a parent scope is already active then the childscope will become a part of it unless otherwise specified.

Dim ItemCount As Int32 = 1 * (10 ^ 3)
Using CS1 As New CachingScope
    
    Console.WriteLine("Adding Objects in Base scope")
    For i As Int32 = 1 To ItemCount
       CachingService.PutCacheItem("ItemName" & i, "Value " & i)
    Next
    
    Console.WriteLine("Reading Objects with no lock")
    Dim O1 As Object
    For i As Int32 = 1 To ItemCount
       O1 = CachingService.GetCacheItem("ItemName" & i)
    Next
    
End Using

Region checking is also built into the put functions so that you don't have to figure out if you should add it or not. It's done under the covers for you.

Last edited Feb 17, 2009 at 2:19 PM by amiddlet, version 9