Exemplo n.º 1
0
        /// <summary>
        /// Returns FieldType object from cache.  If fieldType does not already exist in cache, it
        /// will be read and added to cache
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static FieldTypeCache Read(int id)
        {
            string cacheKey = FieldTypeCache.CacheKey(id);

            ObjectCache    cache     = MemoryCache.Default;
            FieldTypeCache fieldType = cache[cacheKey] as FieldTypeCache;

            if (fieldType != null)
            {
                return(fieldType);
            }
            else
            {
                Rock.Model.FieldTypeService fieldTypeService = new Rock.Model.FieldTypeService();
                Rock.Model.FieldType        fieldTypeModel   = fieldTypeService.Get(id);
                if (fieldTypeModel != null)
                {
                    fieldType = CopyModel(fieldTypeModel);

                    cache.Set(cacheKey, fieldType, new CacheItemPolicy());

                    return(fieldType);
                }
                else
                {
                    return(null);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns FieldType object from cache.  If fieldType does not already exist in cache, it
        /// will be read and added to cache
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static FieldTypeCache Read( int id )
        {
            string cacheKey = FieldTypeCache.CacheKey( id );

            ObjectCache cache = MemoryCache.Default;
            FieldTypeCache fieldType = cache[cacheKey] as FieldTypeCache;

            if ( fieldType != null )
                return fieldType;
            else
            {
                Rock.Model.FieldTypeService fieldTypeService = new Rock.Model.FieldTypeService();
                Rock.Model.FieldType fieldTypeModel = fieldTypeService.Get( id );
                if ( fieldTypeModel != null )
                {
                    fieldType = CopyModel( fieldTypeModel );

                    cache.Set( cacheKey, fieldType, new CacheItemPolicy() );

                    return fieldType;
                }
                else
                    return null;
            }
        }