Private cache program3/21/2023 New CachedProductRepository(new SqlProductRepository())) This is incredibly useful later when you get a confusing bug that you suspect is a result of the cache. You can now instantiate the ProductManager with either of those Repositories and get caching. See how you've removed the repository implementation knowledge from the ProductManager? See also how you've adhered to Single Responsibility Principle by having a class that handles data extraction, a class that handles data retrieval and a class that handles caching? if not then call GetAll() on inner repository Public CachedProductRepository (IProductRepository productRepository) Private IProductRepository ProductRepository Just have a Repository and a Caching Wrapper that use the same interface and inject that into the calling class. However, if this is the only thing you're caching, you don't need to go as far as having an AOP framework. Using tools like PostSharp, you can set it up so that any method marked with a chosen attribute will be cached. It's one of the few things that it's very good at. Second, wrap the class that gets the data from the database (or wherever) in a caching wrapper.ĪOP is a good technique for this. It no longer cares where you're getting it from. This makes testing your filtering class nice and easy. That it retrieves from the cache is an implementation detail of the repository and shouldn't be known by the calling code. The Single Responsibility Principle is your best friend here.įirst of all, move AllFromCache() into a repository class and call it GetAll().
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |