public async Task <DataPortalResult> Fetch(Type objectType, object criteria, DataPortalContext context, bool isSync) { var cachingAttribute = ObjectCacheAttribute.GetObjectCacheAttribute(objectType); var cacheProvider = CacheManager.GetCacheProvider(); if (cachingAttribute != null && cacheProvider != null) { //get scenario details var scope = cachingAttribute.Scope; var cacheByCriteria = cachingAttribute.CacheByCriteria; var expiration = cachingAttribute.Expiration; //get key var key = GetCacheItemKey(objectType, cachingAttribute); //include criteria hash if needed if (cachingAttribute.CacheByCriteria) { key = string.Format("{0}::{1}", key, criteria.GetHashCode()); } var data = cacheProvider.Get(key); if (data == null) { //cache miss proxy = GetDataPortalProxy(); var results = await proxy.Fetch(objectType, criteria, context, isSync); if (expiration > 0) { cacheProvider.Put(key, results.ReturnObject, new TimeSpan(0, expiration, 0)); } else { cacheProvider.Put(key, results.ReturnObject); } return(results); } else { //cache hit #if !NET45 && !NET46 await TaskEx.Delay(0); #else await Task.Delay(0); #endif return(new DataPortalResult(data)); } } else { proxy = GetDataPortalProxy(); return(await proxy.Fetch(objectType, criteria, context, isSync)); } }
public DataPortalResult Fetch(Type objectType, object criteria, DataPortalContext context) { var cachingAttribute = ObjectCacheAttribute.GetObjectCacheAttribute(objectType); var cacheProvider = CacheManager.GetCacheProvider(); if (cachingAttribute != null && cacheProvider != null) { //get scenario details var scope = cachingAttribute.Scope; var cacheByCriteria = cachingAttribute.CacheByCriteria; var expiration = cachingAttribute.Expiration; //get key var key = GetCacheItemKey(objectType, cachingAttribute); //include criteria hash if needed if (cachingAttribute.CacheByCriteria) { key = string.Format("{0}::{1}", key, criteria.GetHashCode()); } var data = cacheProvider.Get(key); if (data == null) { //cache miss proxy = GetDataPortalProxy(); var results = proxy.Fetch(objectType, criteria, context); if (expiration > 0) { cacheProvider.Put(key, results, new TimeSpan(0, expiration, 0)); } else { cacheProvider.Put(key, results); } return(results); } else { //cache hit return((DataPortalResult)data); } } else { proxy = GetDataPortalProxy(); return(proxy.Fetch(objectType, criteria, context)); } }
/// <summary> /// Test cache system configuration and type declaration /// </summary> /// <param name="objectType">Target business object type</param> /// <returns>True if configuration is valid and type has ObjectCacheAttribute; else false</returns> public static bool IsCacheConfigured(Type objectType) { return(ObjectCacheAttribute.GetObjectCacheAttribute(objectType) != null && GetCacheProvider() != null); }