Class for bunding multiple files into one.
示例#1
0
        public static void AddBundleToCache(Bundle bundle)
        {
            Bundle alreadyThere;

            _bundlesLock.EnterReadLock();

            try
            {
                alreadyThere = _bundles.SingleOrDefault(x => x.Hash == bundle.Hash);
            }
            finally 
            {
                _bundlesLock.ExitReadLock();
            }

            if (alreadyThere == null)
            {
                AddBundleIfNotThere(bundle);
            }
            else
            {
                bundle = alreadyThere;
            }

            lock (bundle)
            {
                if (!IsBundleInCache(bundle))
                {
                    var result = bundle.Combine();
                    _cache.Set(bundle.Hash, result, new CacheItemPolicy() { AbsoluteExpiration = bundle.LastCacheInvalidationDate.AddDays(7) });
                }
            }
        }
示例#2
0
        public static void AddBundleIfNotThere(Bundle b)
        {
            if (!b.IsClosed)
                throw new Exception("You can only add closed bundles to the BundleHandler, sorry.");

            Bundle alreadyThere;

            _bundlesLock.EnterReadLock();
            
            try
            {
                alreadyThere = _bundles.SingleOrDefault(x => x.Hash == b.Hash);
            }
            finally 
            {
                _bundlesLock.ExitReadLock();
            }

            if (alreadyThere == null)
            {
                _bundlesLock.EnterWriteLock();

                try
                {
                    alreadyThere = _bundles.SingleOrDefault(x => x.Hash == b.Hash);

                    if (alreadyThere == null)
                    {
                        b.LastCacheInvalidationDate = DateTime.Now;
                        _bundles.Add(b);
                    }
                }
                finally 
                {
                    _bundlesLock.ExitWriteLock();
                }
            }
            else
            {
                b.LastCacheInvalidationDate = alreadyThere.LastCacheInvalidationDate;
            }
        }
示例#3
0
 public static bool IsBundleInCache(Bundle b)
 {
     return (_cache[b.Hash] as string) != null;
 }