Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static string GetCacheElementSuffix(string name)
        {
            // get the section
            CacheSection section = CacheSectionManager.CacheSection;
            CacheElement item    = null;
            // get the element from web.config
            IEnumerator enumerator = section.CacheElementCollection.GetEnumerator();

            while (enumerator.MoveNext())
            {
                if (((CacheElement)enumerator.Current).Name.Equals(name))
                {
                    item = ((CacheElement)enumerator.Current);
                    break;
                }
            }

            // throw exception if the element was not found
            if (item == null)
            {
                throw new CachingException("Cache object \"" + name + "\" not found at the CacheElementCollection collection.");
            }

            return(item.Suffix);
        }
Exemple #2
0
        private void Init()
        {
            // get the name of this object
            string name = this.GetType().Name;

            // get the section
            _Section = CacheSectionManager.CacheSection;

            // get the element from web.config
            IEnumerator enumerator = _Section.CacheElementCollection.GetEnumerator();

            while (enumerator.MoveNext())
            {
                if (((CacheElement)enumerator.Current).Name.Equals(name))
                {
                    _Item = ((CacheElement)enumerator.Current);
                    break;
                }
            }

            // throw exception if the element was not found
            if (_Item == null)
            {
                throw new CachingException("Cache object \"" + name + "\" not found at the CacheElementCollection collection.");
            }

            if (_Item.IsIterating && string.IsNullOrEmpty(_EnumerationKey))
            {
                throw new CachingException("Enumeration key not set on an enumerating object. Please define the enumeration key at the constructor.");
            }

            // get the global cachesettings
            if (_Item.Minutes <= 0 && _Item.Seconds <= 0)
            {
                _Item.Minutes = _Section.CacheElementCollection.Minutes;
            }

            _UseCache = _Section.CacheElementCollection.Enabled;

            _IsInitialized = true;
        }