Esempio 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);
        }
Esempio n. 2
0
            public bool MoveNext()
            {
                currentEntry = default(DictionaryEntry);
                // if index points to pre-1st element...
                if (_keyIndex < 0)
                {
                    _keyIndex++;
                    _store.Locker.Lock(OperationType.Read);
                    try
                    {
                        if (_store.Search(_keys[_keyIndex], true))
                        {
                            currentEntry = _store.CurrentEntry;
                            return(true);
                        }
                    }
                    finally
                    {
                        _store.Locker.Unlock(OperationType.Read);
                    }

                    while (++_keyIndex <= _keys.Length - 1)
                    {
                        _store.Locker.Lock(OperationType.Read);
                        try
                        {
                            if (_store.Search(_keys[_keyIndex], true))
                            {
                                currentEntry = _store.CurrentEntry;
                                return(true);
                            }
                        }
                        finally
                        {
                            _store.Locker.Unlock(OperationType.Read);
                        }
                    }
                    return(false);
                }
                // move store pointer to next element and if it has same key as current one in keys array,
                // just return true so Store can return this element.
                _store.Locker.Lock(OperationType.Read);
                try
                {
                    if (_store.MoveNext() &&
                        _store.Comparer.Compare(_store.CurrentKey, _keys[_keyIndex]) == 0)
                    {
                        currentEntry = _store.CurrentEntry;
                        return(true);
                    }
                }
                finally
                {
                    _store.Locker.Unlock(OperationType.Read);
                }
                while (++_keyIndex <= _keys.Length - 1)
                {
                    _store.Locker.Lock(OperationType.Read);
                    try {
                        if (_store.Search(_keys[_keyIndex], true))
                        {
                            currentEntry = _store.CurrentEntry;
                            return(true);
                        }
                    }
                    finally
                    {
                        _store.Locker.Unlock(OperationType.Read);
                    }
                }
                return(false);
            }
Esempio n. 3
0
 public bool MoveNext()
 {
     currentEntry = default(DictionaryEntry);
     // if index points to pre-1st element...
     if (_wasReset)
     {
         _wasReset = false;
         if (!_source.MoveNext())
         {
             return(false);
         }
         _target.Locker.Lock(OperationType.Read);
         try
         {
             if (_target.Search(_sourceKeyExtractor(_source.Current), true))
             {
                 currentEntry = _target.CurrentEntry;
                 return(true);
             }
         }
         finally
         {
             _target.Locker.Unlock(OperationType.Read);
         }
         while (_source.MoveNext())
         {
             _target.Locker.Lock(OperationType.Read);
             try
             {
                 if (_target.Search(_sourceKeyExtractor(_source.Current), true))
                 {
                     currentEntry = _target.CurrentEntry;
                     return(true);
                 }
             }
             finally
             {
                 _target.Locker.Unlock(OperationType.Read);
             }
         }
         return(false);
     }
     // move store pointer to next element and if it has same key as current one in keys array,
     // just return true so Store can return this element.
     _target.Locker.Lock(OperationType.Read);
     try
     {
         if (_target.MoveNext() &&
             _target.Comparer.Compare(_target.CurrentKey, _sourceKeyExtractor(_source.Current)) == 0)
         {
             currentEntry = _target.CurrentEntry;
             return(true);
         }
     }
     finally
     {
         _target.Locker.Unlock(OperationType.Read);
     }
     while (SourceMoveNextUniqueKey())
     {
         _target.Locker.Lock(OperationType.Read);
         try
         {
             if (_target.Search(_sourceKeyExtractor(_source.Current), true))
             {
                 currentEntry = _target.CurrentEntry;
                 return(true);
             }
         }
         finally
         {
             _target.Locker.Unlock(OperationType.Read);
         }
     }
     return(false);
 }