Ignore:
Timestamp:
30.08.2009 18:58:35 (3 years ago)
Author:
stoecker
Message:

fixed #3289 - patch by xeen - cache.wmsplugin.expire and cache.wmsplugin.maxsize are not honored

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/CacheFiles.java

    r1705 r2016  
    5555     */ 
    5656    public CacheFiles(String ident) { 
    57        String pref = Main.pref.getPluginsDirFile().getPath(); 
    58        boolean dir_writeable; 
    59        this.ident = ident; 
    60        String cacheDir = Main.pref.get("cache." + ident + "." + "path", pref + "/" + ident + "/cache/"); 
    61        this.dir = new File(cacheDir); 
    62        try { 
    63            this.dir.mkdirs(); 
    64            dir_writeable = true; 
     57        String pref = Main.pref.getPluginsDirFile().getPath(); 
     58        boolean dir_writeable; 
     59        this.ident = ident; 
     60        String cacheDir = Main.pref.get("cache." + ident + "." + "path", pref + "/" + ident + "/cache/"); 
     61        this.dir = new File(cacheDir); 
     62        try { 
     63            this.dir.mkdirs(); 
     64            dir_writeable = true; 
    6565        } catch(Exception e) { 
    66            // We have no access to this directory, so don't to anything 
    67            dir_writeable = false; 
     66            // We have no access to this directory, so don't do anything 
     67            dir_writeable = false; 
    6868        } 
    6969        this.enabled = dir_writeable; 
    7070        this.expire = Main.pref.getLong("cache." + ident + "." + "expire", EXPIRE_DAILY); 
    71         if(this.expire < 0) 
     71        if(this.expire < 0) { 
    7272            this.expire = CacheFiles.EXPIRE_NEVER; 
     73        } 
    7374        this.maxsize = Main.pref.getLong("cache." + ident + "." + "maxsize", 50); 
    74         if(this.maxsize < 0) 
     75        if(this.maxsize < 0) { 
    7576            this.maxsize = -1; 
     77        } 
    7678    } 
    7779 
     
    9496 
    9597            // Update last mod time so we don't expire recently used data 
    96             if(updateModTime) 
     98            if(updateModTime) { 
    9799                data.setLastModified(new Date().getTime()); 
     100            } 
    98101 
    99102            byte[] bytes = new byte[(int) data.length()]; 
     
    115118        try { 
    116119            File f = getPath(ident); 
    117             if(f.exists()) 
     120            if(f.exists()) { 
    118121                f.delete(); 
     122            } 
    119123            // rws also updates the file meta-data, i.e. last mod time 
    120124            new RandomAccessFile(f, "rws").write(data); 
     
    144148            } 
    145149            // Update last mod time so we don't expire recently used images 
    146             if(updateModTime) 
     150            if(updateModTime) { 
    147151                img.setLastModified(new Date().getTime()); 
     152            } 
    148153            return ImageIO.read(img); 
    149154        } catch(Exception e) { 
     
    177182     */ 
    178183    public void setExpire(int amount, boolean force) { 
    179         if(amount < 0) 
    180             this.expire = EXPIRE_NEVER; 
    181         else 
    182             this.expire = amount; 
    183184        String key = "cache." + ident + "." + "expire"; 
    184         if(force || !Main.pref.hasKey(key)) 
    185             Main.pref.putLong(key, this.expire); 
     185        if(Main.pref.hasKey(key) && !force) 
     186            return; 
     187 
     188        this.expire = amount > 0 ? amount : EXPIRE_NEVER; 
     189        Main.pref.putLong(key, this.expire); 
    186190    } 
    187191 
     
    192196     */ 
    193197    public void setMaxSize(int amount, boolean force) { 
     198        String key = "cache." + ident + "." + "maxsize"; 
     199        if(Main.pref.hasKey(key) && !force) 
     200            return; 
     201 
    194202        this.maxsize = amount > 0 ? amount : -1; 
    195         String key = "cache." + ident + "." + "maxsize"; 
    196         if(force || !Main.pref.hasKey(key)) 
    197             Main.pref.putLong(key, this.maxsize); 
     203        Main.pref.putLong(key, this.maxsize); 
    198204    } 
    199205 
     
    211217     */ 
    212218    public void checkCleanUp() { 
    213         if(this.writes > this.cleanUpInterval) 
     219        if(this.writes > this.cleanUpInterval) { 
    214220            cleanUp(); 
     221        } 
    215222    } 
    216223 
     
    225232 
    226233        for(File f : dir.listFiles()) { 
    227             if(isExpired(f)) 
     234            if(isExpired(f)) { 
    228235                f.delete(); 
    229             else { 
     236            } else { 
    230237                dirsize += f.length(); 
    231238                modtime.put(f.lastModified(), f); 
     
    259266    public void customCleanUp(int type, int size) { 
    260267        switch(type) { 
    261             case CLEAN_ALL: 
    262                 for(File f : dir.listFiles()) 
     268        case CLEAN_ALL: 
     269            for(File f : dir.listFiles()) { 
     270                f.delete(); 
     271            } 
     272            break; 
     273        case CLEAN_SMALL_FILES: 
     274            for(File f: dir.listFiles()) 
     275                if(f.length() < size) { 
    263276                    f.delete(); 
    264                 break; 
    265             case CLEAN_SMALL_FILES: 
    266                 for(File f: dir.listFiles()) 
    267                     if(f.length() < size) 
    268                         f.delete(); 
    269                 break; 
    270             case CLEAN_BY_DATE: 
    271                 cleanUp(); 
    272                 break; 
     277                } 
     278            break; 
     279        case CLEAN_BY_DATE: 
     280            cleanUp(); 
     281            break; 
    273282        } 
    274283    } 
     
    282291        long dirsize = 0; 
    283292 
    284         for(File f : this.dir.listFiles()) 
     293        for(File f : this.dir.listFiles()) { 
    285294            dirsize += f.length(); 
     295        } 
    286296        return dirsize; 
    287297    } 
Note: See TracChangeset for help on using the changeset viewer.