/// <summary>Add a new index to the cache</summary> /// <typeparam name="KeyType">the type of the key value</typeparam> /// <param name="indexName">the name to be associated with this list</param> /// <param name="getKey">delegate to get key from object</param> /// <param name="loadItem">delegate to load object if it is not found in index</param> /// <returns>the newly created index</returns> public IIndex <KeyType> AddIndex <KeyType>(String indexName, GetKeyFunc <KeyType, ItemType> getKey, GetValueFunc <KeyType, ItemType> loadItem) { var index = new Index <KeyType>(this, getKey, loadItem); _indexList[indexName] = index; return(index); }
/// <summary>Add a new index to the cache</summary> /// <typeparam name="TKey">the type of the key value</typeparam> /// <param name="indexName">the name to be associated with this list</param> /// <param name="getKey">delegate to get key from object</param> /// <param name="loadItem">delegate to load object if it is not found in index</param> /// <returns>the newly created index</returns> public IIndex <TKey> AddIndex <TKey>(String indexName, GetKeyFunc <TKey> getKey, LoadItemFunc <TKey> loadItem) { var index = new Index <TKey>(this, getKey, loadItem); _indexList[indexName] = index; return(index); }
/// <summary>constructor</summary> /// <param name="owner">parent of index</param> /// <param name="getKey">delegate to get key from object</param> /// <param name="loadItem">delegate to load object if it is not found in index</param> public Index(LruItemCache <TItem> owner, GetKeyFunc <TKey> getKey, LoadItemFunc <TKey> loadItem) { _owner = owner; _index = new Dictionary <TKey, WeakReference>(_owner._capacity * 2); _getKey = getKey; _loadItem = loadItem; RebuildIndex(); }
/// <summary>constructor</summary> /// <param name="owner">parent of index</param> /// <param name="getKey">delegate to get key from object</param> /// <param name="loadItem">delegate to load object if it is not found in index</param> public Index(LruCache <ItemType> owner, GetKeyFunc <KeyType, ItemType> getKey, GetValueFunc <KeyType, ItemType> loadItem) { Debug.Assert(owner != null, "owner argument required"); Debug.Assert(getKey != null, "GetKey delegate required"); _owner = owner; _index = new Dictionary <KeyType, WeakReference>(_owner._capacity * 2); _getKey = getKey; _loadItem = loadItem; RebuildIndex(); }