예제 #1
0
        private void InitializeInternal()
        {
            var type = typeof(T);

            this.Scope       = string.Empty;
            this.IsCacheable = false;
            this.IsScoped    = false;
            this.CacheArgs   = null;

            var scopeAttribute = DataUtil.GetAttribute <ScopeAttribute>(type);

            if (scopeAttribute != null)
            {
                this.Scope = scopeAttribute.Scope;
            }

            this.IsScoped = !string.IsNullOrEmpty(this.Scope);

            var cacheableAttribute = DataUtil.GetAttribute <CacheableAttribute>(type);

            if (cacheableAttribute != null)
            {
                this.IsCacheable = true;
                var cacheKey = !string.IsNullOrEmpty(cacheableAttribute.CacheKey)
                                ? cacheableAttribute.CacheKey
                                : string.Format("OR_{0}", type.Name);
                var cachePriority = cacheableAttribute.CachePriority;
                var cacheTimeOut  = cacheableAttribute.CacheTimeOut;

                if (this.IsScoped)
                {
                    cacheKey += "_" + this.Scope + "_{0}";
                }

                this.CacheArgs = new CacheItemArgs(cacheKey, cacheTimeOut, cachePriority);
            }
        }
        private void Initialize()
        {
            var type = typeof(T);

            Scope       = String.Empty;
            IsCacheable = false;
            IsScoped    = false;
            CacheArgs   = null;

            var scopeAttribute = DataUtil.GetAttribute <ScopeAttribute>(type);

            if (scopeAttribute != null)
            {
                Scope = scopeAttribute.Scope;
            }

            IsScoped = (!String.IsNullOrEmpty(Scope));

            var cacheableAttribute = DataUtil.GetAttribute <CacheableAttribute>(type);

            if (cacheableAttribute != null)
            {
                IsCacheable = true;
                var cacheKey = !String.IsNullOrEmpty(cacheableAttribute.CacheKey)
                                ? cacheableAttribute.CacheKey
                                : String.Format("OR_{0}", type.Name);
                var cachePriority = cacheableAttribute.CachePriority;
                var cacheTimeOut  = cacheableAttribute.CacheTimeOut;

                if (IsScoped)
                {
                    cacheKey += "_" + Scope + "_{0}";
                }

                CacheArgs = new CacheItemArgs(cacheKey, cacheTimeOut, cachePriority);
            }
        }