//-----------------------------------------------------------------------
// 
//     Copyright (c) Microsoft Corporation.
// 
//-----------------------------------------------------------------------
namespace Microsoft.Isam.Esent.Interop
{
    using System.Diagnostics;
    /// 
    /// Static class containing MemoryCaches for different ESENT buffers.
    /// Use these to avoid memory allocations when the memory will be
    /// used for a brief time.
    /// 
    internal static class Caches
    {
        /// 
        /// The maximum key size that any version of ESENT can have for
        /// any page size. This is also the maximum bookmark size.
        /// 
        private const int KeyMostMost = 2000;
        /// 
        /// Reserve 1 extra space for keys made with prefix or wildcard.
        /// 
        private const int LimitKeyMostMost = KeyMostMost + 1;
        /// 
        /// The maximum number of buffers we want in a cache.
        /// 
        private const int MaxBuffers = 16;
        /// 
        /// Cached buffers for columns.
        /// 
        private static readonly MemoryCache TheColumnCache = new MemoryCache(128 * 1024, MaxBuffers);
        /// 
        /// Cached buffers for keys and bookmarks.
        /// 
        private static readonly MemoryCache TheBookmarkCache = new MemoryCache(LimitKeyMostMost, MaxBuffers);
        /// 
        /// Cached buffers for keys and bookmarks.
        /// 
        private static readonly MemoryCache TheSecondaryBookmarkCache = new MemoryCache(LimitKeyMostMost, MaxBuffers);
        /// 
        /// Gets the cached buffers for columns.
        /// 
        public static MemoryCache ColumnCache
        {
            [DebuggerStepThrough]
            get { return TheColumnCache; }
        }
        /// 
        /// Gets the cached buffers for keys and bookmarks.
        /// 
        public static MemoryCache BookmarkCache
        {
            [DebuggerStepThrough]
            get { return TheBookmarkCache; }
        }
        /// 
        /// Gets the cached buffers for keys and secondary bookmarks.
        /// 
        public static MemoryCache SecondaryBookmarkCache
        {
            [DebuggerStepThrough]
            get
            {
                return TheSecondaryBookmarkCache;
            }
        }
    }
}