Esempio n. 1
0
        /// <summary>
        /// Attempts to start the DiskCache using the current settings. Returns true if successful or if already started. Returns false on a configuration error.
        /// Called by Install()
        /// </summary>
        public bool Start()
        {
            if (!IsConfigurationValid())
            {
                return(false);
            }
            lock (_startSync) {
                if (_started)
                {
                    return(true);
                }
                if (!IsConfigurationValid())
                {
                    return(false);
                }

                //Init the writer.
                writer = new WebConfigWriter(this, PhysicalCacheDir);
                //Init the inner cache
                if (!AsyncModuleMode)
                {
                    cache = new CustomDiskCache(this, PhysicalCacheDir, Subfolders, AsyncBufferSize);
                }
                if (AsyncModuleMode)
                {
                    asyncCache = new AsyncCustomDiskCache(this, PhysicalCacheDir, Subfolders, AsyncBufferSize);
                }

                //Init the cleanup strategy
                if (AutoClean && cleanupStrategy == null)
                {
                    cleanupStrategy = new CleanupStrategy();                                       //Default settings if null
                }
                //Init the cleanup worker
                if (AutoClean)
                {
                    cleaner = new CleanupManager(this, AsyncModuleMode ? (ICleanableCache)asyncCache : (ICleanableCache)cache, cleanupStrategy);
                }
                //If we're running with subfolders, enqueue the cache root for cleanup (after the 5 minute delay)
                //so we don't eternally 'skip' files in the root or in other unused subfolders (since only 'accessed' subfolders are ever cleaned ).
                if (cleaner != null)
                {
                    cleaner.CleanAll();
                }

                if (log != null)
                {
                    log.Info("DiskCache started successfully.");
                }
                //Started successfully
                _started = true;
                return(true);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Attempts to start the DiskCache using the current settings. Returns true if succesful or if already started. Returns false on a configuration error.
        /// Called by Install()
        /// </summary>
        public bool Start()
        {
            if (!IsConfigurationValid()) return false;
            lock (_startSync) {
                if (_started) return true;
                if (!IsConfigurationValid()) return false;

                //Init the writer.
                writer = new WebConfigWriter(this,PhysicalCacheDir);
                //Init the inner cache
                cache = new CustomDiskCache(this, PhysicalCacheDir, Subfolders, HashModifiedDate,AsyncBufferSize);
                //Init the cleanup strategy
                if (AutoClean && cleanupStrategy == null) cleanupStrategy = new CleanupStrategy(); //Default settings if null
                //Init the cleanup worker
                if (AutoClean) cleaner = new CleanupManager(this, cache, cleanupStrategy);
                //If we're running with subfolders, enqueue the cache root for cleanup (after the 5 minute delay)
                //so we don't eternally 'skip' files in the root or in other unused subfolders (since only 'accessed' subfolders are ever cleaned ).
                if (cleaner != null) cleaner.CleanAll();

                if (log != null) log.Info("DiskCache started successfully.");
                //Started successfully
                _started = true;
                return true;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Attempts to start the DiskCache using the current settings. Returns true if succesful or if already started. Returns false on a configuration error.
        /// Called by Install()
        /// </summary>
        public bool Start()
        {
            if (!IsConfigurationValid()) return false;
            lock (_startSync)
            {
                if (_started) return true;
                if (!IsConfigurationValid()) return false;

                //Init the writer.
                writer = new WebConfigWriter(this, PhysicalCacheDir);
                //Init the inner cache
                cache = new CustomDiskCache(this, PhysicalCacheDir, 512, true, 1024 * 1024 * 30); //30MB
                //Init the cleanup strategy
                var cleanupStrategy = new CleanupStrategy(); //Default settings if null
                cleanupStrategy.TargetItemsPerFolder = 50;
                //Init the cleanup worker
                cleaner = new CleanupManager(this, cache, cleanupStrategy);
                //If we're running with subfolders, enqueue the cache root for cleanup (after the 5 minute delay)
                //so we don't eternally 'skip' files in the root or in other unused subfolders (since only 'accessed' subfolders are ever cleaned ).
                if (cleaner != null) cleaner.CleanAll();

                //Started successfully
                _started = true;
                return true;
            }
        }