示例#1
0
    public CacheItem Get(string key)
    {
        CacheItem item = null;
        ReadOnlyCollection <string> keys = _CacheKeysReadOnly;

        if (!keys.Contains(key))
        {
            lock (_SynchObj)
            {
                keys = _CacheKeysReadOnly;
                if (!keys.Contains(key))
                {
                    item = new CacheItem();
                    item.ExpensiveLoad();
                    _Cache.Add(key, item);
                    List <string> newKeys = new List <string>(_CacheKeysReadOnly);
                    newKeys.Add(key);
                    _CacheKeysReadOnly = newKeys.AsReadOnly();
                }
            }
        }
        return(item);
    }