Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
alastairtree committed Apr 6, 2014
1 parent 3a84c91 commit a1bc7d4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
5 changes: 5 additions & 0 deletions LazyCache.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LazyCache", "LazyCache\Lazy
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LazyCache.UnitTests", "LazyCache.UnitTests\LazyCache.UnitTests.csproj", "{7F6C8799-CA9E-43BD-AE97-72C31BB4E106}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "info", "info", "{81C0E096-59B7-4129-851B-8183FDB9B02B}"
ProjectSection(SolutionItems) = preProject
Readme.md = Readme.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
40 changes: 36 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,36 @@
LazyCache
=========

A thread safe generics based in memory caching service with a simple developer friendly API for c#
# Lazy Cache #

Lazy cache is a simple in-memory caching service. It has a developer friendly generics based API, and providing a thread safe cache implementation that guarantees to only execute your cachable delegates once (it's lazy!). Under the hood it leverages ObjectCache and Lazy<T> to provide performance and reliability in heavy load scenarios

## Example ##

// Declare (but don't execute) a func whose result we want to cache
Func<ComplexObects> complexObjectFactory = () => methodThatTakesTimeOrResources();

// Get hold of the cache (Dependency injection would be better).
// Uses MemoryCache.Default under the hood so cache is shared
IAppCache cache = new CachingService();

// If we have generated the complexObject recently return the
// cached instances, otherwise build and cache them for later
ComplexObject cachedResults = cache.GetOrAdd("uniqueKey", complexObjectFactory);

As you can see the magic happens in the `GetOrAdd()` method which gives the consumer an atomic and tidy way to add caching to your code, with a delegate func to optionally invoke the code for slow results you want to cache. It means you avoid the usual "Check the cache - generate - add to the cache" pattern and can be a lazy developer!

## Use case ##

Suits the caching of database calls, complex object graph building routines and web service calls that should be cached for performance. Allows items to be cached for long or short periods, but defaults to 20 mins.

## Features ##

- Simple API with easy sliding and absolute expiration
- Guaranteed single evaluation of you long running code whose results you want to cache
- Strongly typed generics based API. No need to cast your cached objects every time
- Thread safe, concurrency ready
- Leverages ObjectCache under the hood and can be extended with your own implementation of the ObjectCache object
- Good test coverage
- `CachingSevice` is a single class and so could be simply embedded
- Interface based API and built in `MockCache` to support test driven development

## To do ##
- Create a nuget package for LazyCache

0 comments on commit a1bc7d4

Please sign in to comment.