Ejemplo n.º 1
0
        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));
            }
        }
Ejemplo n.º 2
0
        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));
            }
        }
        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);
            }
        }
        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
                    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);
            }
        }