Logo Search packages:      
Sourcecode: bareftp version File versions  Download package

FileListCache.cs

// FileListCache.cs
//
//  Copyright (C) 2008-2009 Christian Eide
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
using System;
using System.Collections.Generic;

// TODO: Make some kind of periodical cleaning of cache
// TODO: Actually use this cache

namespace bareFTP.Gui.FileManager
{
      public class FileListCache
    {
      private int timeout;
      private List<CacheEntry> cache;
      
      public FileListCache(int cache_timeout)
      {
            this.timeout = cache_timeout;
            this.cache = new List<CacheEntry>();
            
      }
      
      public Gtk.ListStore GetCachedStore(string directory)
      {
            //Console.WriteLine("S√łker: " + directory);
            for(int x=0;x<cache.Count;x++)
            {     
                  //Console.WriteLine("Sammenlikner: " + cache[x].Directory);
                  if(directory == cache[x].Directory)
                  {
                        if(cache[x].Timestamp.AddSeconds(timeout) > DateTime.Now)
                        {
                              //Console.WriteLine("Fant cache");
                              return cache[x].Store;
                        }
                        else
                        {
                              cache.RemoveAt(x);
                              return null;
                        }
                  }
            }
            return null;
      }
      
      public void AddEntry(string directory, Gtk.ListStore store)
      {
            CacheEntry entry = new CacheEntry(directory, store);
            bool haveold = false;
            
            for(int x=0;x<cache.Count;x++)
            {
                  if(entry.Directory == cache[x].Directory)
                  {
                        cache[x] = entry;
                        haveold = true;
                        break;
                  }
            }
            if(!haveold)
                  cache.Add(entry);
            
      }
    }
    
    public class CacheEntry
    {
      private string dir;
      private DateTime time;
      private Gtk.ListStore store;
      
      public CacheEntry(string directory, Gtk.ListStore store)
      {
            this.dir = directory;
            this.time = DateTime.Now;
            this.store = store;
      }
      
      #region Properties
      
      public string Directory
      {
            get {return dir;}
      }
      public DateTime Timestamp
      {
            get {return time;}
      }
      public Gtk.ListStore Store
      {
            get {return store;}
      }
      
      #endregion
    }
}

Generated by  Doxygen 1.6.0   Back to index