コード例 #1
0
        private CachedSpellCheckData JustCheckCore(string word)
        {
            _cacheLock.EnterUpgradeableReadLock();
            try {
                CachedSpellCheckData result;
                if (_cache.TryGetValue(word, out result))
                {
                    return(result);
                }

                _cacheLock.EnterWriteLock();
                try {
                    while (_cache.Count >= _cacheMax)
                    {
                        _cache.Remove(_cache.Keys.First());
                    }

                    _cache[word] = result = new CachedSpellCheckData(_core.Check(word));
                }
                finally {
                    _cacheLock.ExitWriteLock();
                }
                return(result);
            }
            finally {
                _cacheLock.ExitUpgradeableReadLock();
            }
        }
コード例 #2
0
        private CachedSpellCheckData GetRecommendationsCore(string word)
        {
            _cacheLock.EnterUpgradeableReadLock();
            try {
                CachedSpellCheckData result;
                bool?wordFound = null;
                if (_cache.TryGetValue(word, out result))
                {
                    if (result.Suggestions != null)
                    {
                        return(result);
                    }

                    wordFound = result.WordFound;
                }

                _cacheLock.EnterWriteLock();
                try
                {
                    if (!wordFound.HasValue)
                    {
                        wordFound = _core.Check(word);
                    }

                    while (_cache.Count >= _cacheMax)
                    {
                        _cache.Remove(_cache.Keys.First());                         // TODO: this could be a lot better
                    }
                    _cache[word] = result = new CachedSpellCheckData(wordFound.Value, _core.GetRecommendations(word));
                }
                finally {
                    _cacheLock.ExitWriteLock();
                }
                return(result);
            }
            finally {
                _cacheLock.ExitUpgradeableReadLock();
            }
        }