Skip to content

Instantly share code, notes, and snippets.

@adamtuliper
Created September 14, 2012 03:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamtuliper/3719567 to your computer and use it in GitHub Desktop.
Save adamtuliper/3719567 to your computer and use it in GitHub Desktop.
Strongly typed caching
public void Test_Add_And_Remove_Item_From_Cache_Pass()
{
Customer customer = new Customer
{
CustomerId = new Random(DateTime.Now.Millisecond).Next(),
FirstName = "Mary",
LastName = "Doe",
Address = "555 Main St.",
City = "Austin",
State = "TX",
Zip = "73301",
EmailAddress = "mary@internal"
};
string customerId = customer.CustomerId.ToString();
//Act (add and remove from cache, then attempt to retrieve)
_cache.Add(customerId, customer, 100);
_cache.Remove(customerId);
var cachedCustomer = _cache.Get<Customer>(customerId);
//Assert - should be null
Assert.IsNull(cachedCustomer);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment