Ejemplo n.º 1
0
        /// <summary>
        /// marks cacheable element as unused
        /// </summary>
        /// <param name="baseName"></param>
        public void MarkUnused(string baseName)
        {
            //LibSys.StatusBar.Trace("OK: MyCache:MarkUnused() - tile '" + baseName + "'");

            if (this.Contains(baseName))
            {
                MyCacheable mc = (MyCacheable)this[baseName];
                if (mc != null)
                {
                    mc.MarkUnused();
                }
                else
                {
                    // non-existent object behind the name, just remove the name:
                    this.Remove(baseName);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// remove old unused elements from cache
        /// </summary>
        /// <param name="cacheMinCount"></param>
        public void purge(int cacheMinCount)
        {
            //LibSys.StatusBar.Trace("IP: MyCache:purge()");

            SortedList list = new SortedList();             // will contain ticks-based string keys, oldest first:
            int        cnt  = countUnused();

            if (cnt <= cacheMinCount)
            {
                //LibSys.StatusBar.Trace("    too few unused yet: " + cnt);
            }
            else
            {
                int toTrim = cnt - cacheMinCount;
                foreach (MyCacheable mc in this.Values)
                {
                    if (mc != null && !mc.IsUsed)
                    {
                        long lKey = mc.LastUsed;
                        while (list.Contains(lKey))                             // SortedList doesn't tolerate repeated keys
                        {
                            lKey--;
                        }
                        list.Add(lKey, mc.BaseName);
                        if (--toTrim <= 0)
                        {
                            break;
                        }
                    }
                }
                for (int i = 0; i < list.Count; i++)
                {
                    string key = (string)list.GetByIndex(i);
                    //LibSys.StatusBar.Trace("      OK: removing " + this[key]);
                    // all bitmaps and features need to be disposed before they are removed from cache.
                    // disposing of bitmaps releases files from which they were loaded.
                    MyCacheable mc = (MyCacheable)this[key];
                    mc.Dispose();
                    this.Remove(key);
                }
            }
        }