I am working on an application where i intend to load requested data and cache the items for subsequent requests to the same item.
If the item isn't in the cache i intend to make a database call and cache the desired items into a collection for later use.
This is the
Product entity:
ProductID
ProductName
ProductType
ProductPrice
I am using ODP.NET and C# to load the records.
Currently i can load all the products by invoking:
dbProvider.GetAllProducts();
But this is obviously not a good idea for filtering the products so i have created a method to load the products in one or more ways: By List of ProductID, List of ProductName and/or List of ProductTypes.
This is because the end user will be providing a List which can be either be
List of ProductIDs And/Or List of ProductNames And/Or List of ProductTypes.
I want to filter the cache using the List of ProductsIDs and/Or List of ProductNames and/or List of ProductTypes.
What I have tried:
As i am using the repository pattern i extended my ProductsRepository to load the filtered products:
IEnumerable<productdao> loadedProducts = dbProvider.GetFilteredProducts(List<int>ProductIDs,
List<string>ProductNames,
List<string>ProductTypes);
i have started to write the code to cache but i am having issues with implementing what i want to achieve.
ObjectCache cache = MemoryCache.Default;
CacheItemPolicy policy = new CacheItemPolicy();
policy.AbsoluteExpiration = DateTimeOffset.Now.AddMinute(120.0);
IEnumerable<product> loadedProducts dbProvider.GetFilteredProducts(List<int>ProductIDs,
List<string>ProductNames,
List<string>ProductTypes);
...
Once i have cached the items I want to use it in my ProductBusinessLogic class to filter the cache using the List of parameters the user has provided. Is this possible?
How would i check the cache based on what the user has provided e.gList of ProductIds or List of ProductTypes or List of ProductNames.
How would i store the loaded Products from the database into the cache correctly, knowing that the user can request to access the data based on 3 particular ways?