Exemplo n.º 1
0
        /// <summary>
        /// Sample code that uses this VirtualCache.
        /// </summary>
        public static void Run()
        {
            Console.WriteLine("{0}: Virtual Cache demo started...", DateTime.Now);
            MemoryExtender.ServerPath = "SopBin\\";
            MemoryExtender          vc     = new MemoryExtender();
            ISortedDictionaryOnDisk cache1 = vc.GetObjectCache(1);
            const int MaxCount             = 40000;

            for (int i = 0; i < MaxCount; i++)
            {
                cache1.Add(i, string.Format("{0} cached data", i));
            }

            Console.WriteLine("{0}: Finished inserting {1} records, reading 'em starts now...", DateTime.Now, MaxCount);
            cache1.MoveFirst();
            cache1.HintSequentialRead = true;
            for (int i = 0; i < MaxCount; i++)
            {
                string s = cache1.CurrentValue as string;
                if (string.IsNullOrEmpty(s) ||
                    s != string.Format("{0} cached data", i))
                {
                    Console.WriteLine("Error, data not found.");
                }
                cache1.MoveNext();
            }
            Console.WriteLine("{0}: Virtual Cache demo ended... {1} records were read.", DateTime.Now, MaxCount);
        }
Exemplo n.º 2
0
 private ISortedDictionaryOnDisk CreateCollection(ISortedDictionaryOnDisk container, string storeName)
 {
     return(container.Locker.Invoke(() =>
     {
         ISortedDictionaryOnDisk o;
         if (container.Transaction != null)
         {
             o = ((Transaction.ITransactionLogger)container.Transaction).CreateCollection(
                 container.File, null, storeName, true);
         }
         else
         {
             o = OnDisk.ObjectServer.CreateDictionaryOnDisk(
                 ((OnDisk.Algorithm.SortedDictionary.ISortedDictionaryOnDisk)container).File, null, storeName, true);
         }
         o.Open();
         o.Flush();
         container.Add(o.Name, o);
         o.Container = container;
         return o;
     }));
 }