Changeset 12255 in osm


Ignore:
Timestamp:
2008-12-07T22:09:45+01:00 (16 years ago)
Author:
stephankn
Message:

Enable the user to control the maximum size/age of the lakewalker cache. Close ticket #1808

Location:
applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/LakewalkerAction.java

    r12186 r12255  
    5050  protected Collection<Way> ways = new ArrayList<Way>();
    5151
    52   /** maximum size in bytes for the sum of all tiles in a WMS-layer cache directory. */
    53   private static final long MAXCACHESIZE = 20*1024*1024*1024;
    54 
    55   /** maximum age in ms since epoch for tiles in a WMS-layer cache directory. */
    56   private static final long MAXCACHEAGE = 3650*24*60*60*1000;
    57  
    5852  public LakewalkerAction(String name) {
    5953    super(name, "lakewalker-sml", tr("Lake Walker."),
     
    10094   */
    10195  private void cleanupCache() {
     96          final long maxCacheAge = System.currentTimeMillis()-Main.pref.getInteger(LakewalkerPreferences.PREF_MAXCACHEAGE, 100)*24*60*60*1000L;
     97          final long maxCacheSize = Main.pref.getInteger(LakewalkerPreferences.PREF_MAXCACHESIZE, 300)*1024*1024;
    10298
    10399          for (String wmsFolder : LakewalkerPreferences.WMSLAYERS) {
     
    117113                          // delete aged or oversized, keep newest. Once size/age limit was reached delete all older files
    118114                          long folderSize = 0;
    119                           long timeDefiningOverage = System.currentTimeMillis()-MAXCACHEAGE;
    120115                          boolean quickdelete = false;
    121116                          for (File cacheEntry : wmsCache) {
     
    123118                                  if (!quickdelete) {
    124119                                          folderSize += cacheEntry.length();
    125                                           if (folderSize > MAXCACHESIZE) {
     120                                          if (folderSize > maxCacheSize) {
    126121                                                  quickdelete = true;
    127                                           } else if (cacheEntry.lastModified() < timeDefiningOverage) {
     122                                          } else if (cacheEntry.lastModified() < maxCacheAge) {
    128123                                                  quickdelete = true;
    129124                                          }
  • applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/LakewalkerPlugin.java

    r11924 r12255  
    33import static org.openstreetmap.josm.tools.I18n.tr;
    44
    5 import javax.swing.JMenu;
    6 import javax.swing.JMenuItem;
    7 
    85import org.openstreetmap.josm.Main;
     6import org.openstreetmap.josm.gui.MainMenu;
    97import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
    108import org.openstreetmap.josm.plugins.Plugin;
     
    1715public class LakewalkerPlugin extends Plugin {
    1816  public LakewalkerPlugin() {
    19     Main.main.menu.add(Main.main.menu.toolsMenu, new LakewalkerAction(tr("Lake Walker")));
     17    MainMenu.add(Main.main.menu.toolsMenu, new LakewalkerAction(tr("Lake Walker")));
    2018  }
    2119
  • applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/LakewalkerPreferences.java

    r11938 r12255  
    33import static org.openstreetmap.josm.tools.I18n.tr;
    44
     5import javax.swing.Box;
    56import javax.swing.JLabel;
    67import javax.swing.JPanel;
     
    2930  public static final String PREF_WAYTYPE = "lakewalker.waytype";
    3031  public static final String PREF_WMS = "lakewalker.wms";
     32  public static final String PREF_MAXCACHESIZE = "lakewalker.maxcachesize";
     33  public static final String PREF_MAXCACHEAGE = "lakewalker.maxcacheage";
    3134   
    3235  protected IntConfigurer maxSegsConfig = new IntConfigurer();
     
    5255  protected StringEnumConfigurer wmsConfig = new StringEnumConfigurer(WMSLAYERS);
    5356  protected JLabel wmsLabel = new JLabel(tr("WMS Layer"));
     57  protected IntConfigurer maxCacheSizeConfig = new IntConfigurer();
     58  protected JLabel maxCacheSizeLabel = new JLabel(tr("Maximum cache size (MB)"));
     59  protected IntConfigurer maxCacheAgeConfig = new IntConfigurer();
     60  protected JLabel maxCacheAgeLabel = new JLabel(tr("Maximum cache age (days)"));
    5461 
    5562  public void addGui(PreferenceDialog gui) {
     
    6572    lakeTypeConfig.setToolTipText(tr("Tag ways as water, coastline, land or nothing. Default is water."));
    6673    wmsConfig.setToolTipText(tr("Which WMS layer to use for tracing against. Default is IR1."));
    67 
     74    maxCacheSizeConfig.setToolTipText(tr("Maximum size of each cache directory in bytes. Default is 300MB"));
     75    maxCacheAgeConfig.setToolTipText(tr("Maximum age of each cached file in days. Default is 100"));
     76   
    6877    String description = tr("An plugin to trace water bodies on Landsat imagery.");
    6978    JPanel prefPanel = gui.createPreferenceTab("lakewalker.png", I18n.tr("Lakewalker Plugin Preferences"), description);
     
    8190    lakeTypeConfig.setValue(Main.pref.get(PREF_WAYTYPE, "water"));
    8291    wmsConfig.setValue(Main.pref.get(PREF_WMS, "IR1"));
     92    maxCacheSizeConfig.setValue(Main.pref.getInteger(PREF_MAXCACHESIZE, 300));
     93    maxCacheAgeConfig.setValue(Main.pref.getInteger(PREF_MAXCACHEAGE, 100));
    8394  }
    8495 
     
    109120    prefPanel.add(wmsLabel, labelConstraints);
    110121    prefPanel.add(wmsConfig.getControls(), dataConstraints);
     122    prefPanel.add(maxCacheSizeLabel, labelConstraints);
     123    prefPanel.add(maxCacheSizeConfig.getControls(), dataConstraints);
     124    prefPanel.add(maxCacheAgeLabel, labelConstraints);
     125    prefPanel.add(maxCacheAgeConfig.getControls(), dataConstraints);
     126
     127    prefPanel.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL));
     128
    111129  }
    112130
     
    126144    Main.pref.put(PREF_WAYTYPE, lakeTypeConfig.getValueString());
    127145    Main.pref.put(PREF_WMS, wmsConfig.getValueString());
     146    Main.pref.put(PREF_MAXCACHESIZE, maxCacheSizeConfig.getValueString());
     147    Main.pref.put(PREF_MAXCACHEAGE, maxCacheAgeConfig.getValueString());
    128148  }
    129149 
Note: See TracChangeset for help on using the changeset viewer.