Example #1
0
 const int MaxCacheEntries = 100000;       // 33778;         //10000000;
 private void Populate(ObjectCache target, int count = MaxCacheEntries)
 {
     _logger.Information("{0}: Start of Populating target cache {1}.", DateTime.Now, target.Name);
     for (int i = 0; i < count; i++)
     {
         if (i % 100 == 0)
         {
             _logger.Verbose("Cache Set on item# {0}.", i);
         }
         target.Set(string.Format("Hello{0}", i), string.Format("Value{0}", i), null);
     }
     _logger.Information("{0}: End Populating target cache {1}.", DateTime.Now, target.Name);
 }
Example #2
0
        /// <summary>
        /// Virtual Cache Constructor. Virtual Cache now defaults to being a Memory Extender.
        /// I.e. - Persisted static property defaults to false. Set VirtualCache.Persisted to true
        /// if wanting to persist the cached data across application runs.
        /// </summary>
        /// <param name="storePath">Data Store URI path or the Store name.</param>
        /// <param name="clusteredData">true (default) will configure the Store to save
        /// data together with the Keys in the Key Segment (a.k.a. - clustered),
        /// false will configure Store to save data in its own Data Segment. For small to medium sized
        /// data, Clustered is recommended, otherwise set this to false.</param>
        /// <param name="storeFileName">Valid complete file path where to create the File to contain the data Store.
        /// It will be created if it does not exist yet. Leaving this blank will create the Store within the default
        /// SOP SystemFile, or in the referenced File portion of the storePath, if storePath has a directory path.</param>
        /// <param name="fileConfig">File Config should contain description how to manage data allocations on disk and B-Tree
        /// settings for all the Data Stores of the File. If not set, SOP will use the default configuration.</param>
        public VirtualCacheBase(string storePath, bool clusteredData = true, string storeFileName = null, Sop.Profile fileConfig = null)
        {
            if (string.IsNullOrWhiteSpace(storePath))
            {
                throw new ArgumentNullException("storePath");
            }

            Initialize(fileConfig, Persisted);
            Server.SystemFile.Store.Locker.Invoke(() =>
            {
                SetupStoreFile(storePath, storeFileName, fileConfig);
                _store = Server.StoreNavigator.GetStorePersistentKey <CacheKey, CacheEntry>(storePath,
                                                                                            new StoreParameters <CacheKey>
                {
                    IsDataInKeySegment = clusteredData,
                    AutoFlush          = !clusteredData,
                    StoreKeyComparer   = new CacheKeyComparer(),
                    MruManaged         = false
                });

                Logger = new Log.Logger(string.Format("{0}{2}{1}.txt", _server.Path, _store.Name, System.IO.Path.DirectorySeparatorChar));
                Logger.Verbose("Created/retrieved store {0}.", _store.Name);
            });
        }