Yo dawg! I heard you like cache, so we put a caching mechanism in yo server side cache, so you can cache while you cache!
...but seriously, PLINQO now includes a built in caching mechanism! :)
- All IQueryable result sets can now be dynamically cached/retrieved right from the query.
- The cache is accessible via an IQueryable extension method (FromCache), thus the cached objects are not DataContext specific.
- The cache duration is set at the time of the query, it can be stored for a specific time span or use a sliding expiration.
Example
using (var context = new PetshopDataContext())
{
// Cache a result set. (A query is made to the DB.)
var birds = context.Product.GetByCategoryId("BIRDS").FromCache().ToList();
// Get a single entity from that cache. (No query is made to the DB.)
var firstBird = context.Product.GetByCategoryId("BIRDS").FromCache().FirstOrDefault();
// Specify number of seconds to cache. (A query is made to the DB.)
var penguin = context.Product.GetByName("Penguin").FromCache(60).FirstOrDefault();
// Get the same result set back as a list. (No query is made to the DB.)
var penguins = context.Product.GetByName("Penguin").FromCache(60).ToList();
}
Configuration
This feature is is not yet available in an official PLINQO release, to use the cache you will have to download the latest PLINQO Nightly Build.
To access the FromCache extension method you must...
- Include a reference to the following assemblies...
- CodeSmith.Data
- System.Data.Linq
- System.Data.Services
- System.Web
- Include a using/import statement for the CodeSmith.Data.Linq namespace.
No comments:
Post a Comment