/// <summary>
        /// Get a new cursor for the record. There must NOT be a cached
        /// tableid for the record.
        /// </summary>
        /// <param name="recordId">The id of the record.</param>
        /// <returns>The cursor for the record.</returns>
        public TCursor GetNewCursor(RecordId recordId)
        {
            Debug.Assert(!this.HasCachedCursor(recordId), "There is already a cached cusor for the record");

            CachedCursor victim = this.cachedCursors.OrderBy(x => x.Timestamp).First();

            victim.Timestamp = this.timestamp++;
            victim.Id        = recordId;
            this.Tracer.TraceVerbose("returned new cusor {0} for {1}", victim.Cursor, recordId);
            return(victim.Cursor);
        }
        /// <summary>
        /// Initializes a new instance of the CursorCache class.
        /// </summary>
        /// <param name="openFunc">Delegate used to open a new cursor.</param>
        /// <param name="closeFunc">Delegate used to close a cursor opened by openFunc.</param>
        /// <param name="tablename">The name of the table.</param>
        /// <param name="maxCursors">The number of Cursors to open.</param>
        public CursorCache(Func <TCursor> openFunc, Action <TCursor> closeFunc, string tablename, int maxCursors)
        {
            this.Tracer = new Tracer("CursorCache", "Esent cursor cache", String.Format("CursorCache ({0})", tablename));

            this.openFunc  = openFunc;
            this.closeFunc = closeFunc;

            this.cachedCursors = new List <CachedCursor>(maxCursors);
            for (int i = 0; i < maxCursors; ++i)
            {
                TCursor cursor = this.openFunc();

                var cachedtableid = new CachedCursor
                {
                    Id        = 0,
                    Cursor    = cursor,
                    Timestamp = 0,
                };

                this.cachedCursors.Add(cachedtableid);
                this.Tracer.TraceInfo("cached cursor {0}", cachedtableid.Cursor);
            }
        }