- Timestamp:
- 2009-08-30T18:58:35+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/CacheFiles.java
r1705 r2016 55 55 */ 56 56 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; 65 65 } catch(Exception e) { 66 // We have no access to this directory, so don't to anything67 dir_writeable = false;66 // We have no access to this directory, so don't do anything 67 dir_writeable = false; 68 68 } 69 69 this.enabled = dir_writeable; 70 70 this.expire = Main.pref.getLong("cache." + ident + "." + "expire", EXPIRE_DAILY); 71 if(this.expire < 0) 71 if(this.expire < 0) { 72 72 this.expire = CacheFiles.EXPIRE_NEVER; 73 } 73 74 this.maxsize = Main.pref.getLong("cache." + ident + "." + "maxsize", 50); 74 if(this.maxsize < 0) 75 if(this.maxsize < 0) { 75 76 this.maxsize = -1; 77 } 76 78 } 77 79 … … 94 96 95 97 // Update last mod time so we don't expire recently used data 96 if(updateModTime) 98 if(updateModTime) { 97 99 data.setLastModified(new Date().getTime()); 100 } 98 101 99 102 byte[] bytes = new byte[(int) data.length()]; … … 115 118 try { 116 119 File f = getPath(ident); 117 if(f.exists()) 120 if(f.exists()) { 118 121 f.delete(); 122 } 119 123 // rws also updates the file meta-data, i.e. last mod time 120 124 new RandomAccessFile(f, "rws").write(data); … … 144 148 } 145 149 // Update last mod time so we don't expire recently used images 146 if(updateModTime) 150 if(updateModTime) { 147 151 img.setLastModified(new Date().getTime()); 152 } 148 153 return ImageIO.read(img); 149 154 } catch(Exception e) { … … 177 182 */ 178 183 public void setExpire(int amount, boolean force) { 179 if(amount < 0)180 this.expire = EXPIRE_NEVER;181 else182 this.expire = amount;183 184 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); 186 190 } 187 191 … … 192 196 */ 193 197 public void setMaxSize(int amount, boolean force) { 198 String key = "cache." + ident + "." + "maxsize"; 199 if(Main.pref.hasKey(key) && !force) 200 return; 201 194 202 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); 198 204 } 199 205 … … 211 217 */ 212 218 public void checkCleanUp() { 213 if(this.writes > this.cleanUpInterval) 219 if(this.writes > this.cleanUpInterval) { 214 220 cleanUp(); 221 } 215 222 } 216 223 … … 225 232 226 233 for(File f : dir.listFiles()) { 227 if(isExpired(f)) 234 if(isExpired(f)) { 228 235 f.delete(); 229 else {236 } else { 230 237 dirsize += f.length(); 231 238 modtime.put(f.lastModified(), f); … … 259 266 public void customCleanUp(int type, int size) { 260 267 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) { 263 276 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; 273 282 } 274 283 } … … 282 291 long dirsize = 0; 283 292 284 for(File f : this.dir.listFiles()) 293 for(File f : this.dir.listFiles()) { 285 294 dirsize += f.length(); 295 } 286 296 return dirsize; 287 297 }
Note:
See TracChangeset
for help on using the changeset viewer.