Beispiel #1
0
        public Task AppendEntry(string name, System.IO.Stream data, Int64 offset, Int64 length)
        {
            bool       spaceExists = false;
            CacheEntry e           = null;

            lock (entries)
            {
                bool exists = entries.data.TryGetValue(name, out e);
                if (exists)
                {
                    lock (e)
                    {
                        if (e.InMemory && entries.cachedDataSize + length <= cacheHighWatermark)
                        {
                            entries.cachedDataSize += length;
                            spaceExists             = true;
                        }
                    }
                }
            }

            if (e != null) // the cache entry existed
            {
                lock (e)
                {
                    if (spaceExists) // there's enough space to cache it
                    {
                        return(e.AppendInMemory(data, offset, length, freeList));
                    }
                    else
                    {
                        return(e.AppendSpilling(data, offset));
                    }
                }
            }
            else
            {
                throw new InvalidOperationException("Can't append to unknown IDF " + name);
            }
        }