示例#1
0
        /// <summary>
        /// Gets all cached URL records
        /// </summary>
        /// <returns>cached URL records</returns>
        protected virtual IList <UrlRecordForCaching> GetAllUrlRecordsCached()
        {
            //cache
            string key = string.Format(URLRECORD_ALL_KEY);

            return(_cacheManager.Get(key, () =>
            {
                var query = from ur in _urlRecordRepository.Table
                            select ur;
                var urlRecords = query.ToList();
                var list = new List <UrlRecordForCaching>();
                foreach (var ur in urlRecords)
                {
                    var localizedPropertyForCaching = new UrlRecordForCaching()
                    {
                        Id = ur.Id,
                        EntityId = ur.EntityId,
                        EntityName = ur.EntityName,
                        Slug = ur.Slug,
                        IsActive = ur.IsActive,
                        LanguageId = ur.LanguageId
                    };
                    list.Add(localizedPropertyForCaching);
                }
                return list;
            }));
        }
示例#2
0
        /// <summary>
        /// Find URL record (cached version).
        /// This method works absolutely the same way as "GetBySlug" one but caches the results.
        /// Hence, it's used only for performance optimization in public store
        /// </summary>
        /// <param name="slug">Slug</param>
        /// <returns>Found URL record</returns>
        public virtual UrlRecordForCaching GetBySlugCached(string slug)
        {
            UrlRecordForCaching urlRecordForCaching = null;

            if (String.IsNullOrEmpty(slug))
            {
                return(null);
            }

            if (_localizationSettings.LoadAllUrlRecordsOnStartup)
            {
                //load all records (we know they are cached)
                var source = GetAllUrlRecordsCached();
                var query  = from ur in source
                             where ur.Slug.Equals(slug, StringComparison.InvariantCultureIgnoreCase)
                             //first, try to find an active record
                             orderby ur.IsActive descending, ur.Id
                select ur;
                urlRecordForCaching = query.FirstOrDefault();
            }
            else
            {
                //gradual loading
                var urlRecord = GetBySlug(slug);
                if (urlRecord != null)
                {
                    urlRecordForCaching = Map(urlRecord);
                }
            }

            return(urlRecordForCaching);
        }
 public static UrlRecord Transform(UrlRecordForCaching obj)
 {
     if (obj == null) return null;
     return new UrlRecord
     {
         Id = obj.Id,
         EntityId = obj.EntityId,
         EntityName = obj.EntityName,
         IsActive = obj.IsActive,
         LanguageId = obj.LanguageId,
         Slug = obj.Slug
     };
 }
示例#4
0
        //#region Utilities

        protected UrlRecordForCaching Map(UrlRecord record)
        {
            if (record == null)
            {
                throw new ArgumentNullException("record");
            }

            var urlRecordForCaching = new UrlRecordForCaching
            {
                Id         = record.Id,
                EntityId   = record.EntityId,
                EntityName = record.EntityName,
                Slug       = record.Slug,
                IsActive   = record.IsActive
            };

            return(urlRecordForCaching);
        }