Changeset 1610 in josm


Ignore:
Timestamp:
2009-05-23T11:53:37+02:00 (13 years ago)
Author:
stoecker
Message:

add generic caching class (e.g. for WMS plugin) - patch by xeen

Location:
trunk/src/org/openstreetmap/josm
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/Preferences.java

    r1605 r1610  
    261261    }
    262262
     263    synchronized public boolean putLong(final String key, final Long value) {
     264        return put(key, Long.toString(value));
     265    }
     266
    263267    private final void firePreferenceChanged(final String key, final String value) {
    264268        for (final PreferenceChangedListener l : listener)
  • trunk/src/org/openstreetmap/josm/io/CacheCustomContent.java

    r1450 r1610  
    1111import org.openstreetmap.josm.Main;
    1212
     13/**
     14 * Use this class if you want to cache and store a single file that gets updated regularly.
     15 * Unless you flush() it will be kept in memory. If you want to cache a lot of data and/or files,
     16 * use CacheFiles
     17 * @author xeen
     18 *
     19 */
    1320public abstract class CacheCustomContent {
    1421    /**
     
    2128    final static public int INTERVAL_MONTHLY = INTERVAL_WEEKLY * 4;
    2229    final static public int INTERVAL_NEVER = Integer.MAX_VALUE;
    23    
     30
    2431    /**
    25      * Where the data will be stored   
     32     * Where the data will be stored
    2633     */
    2734    private byte[] data = null;
    28    
     35
    2936    /**
    3037     * The ident that identifies the stored file. Includes file-ending.
    3138     */
    3239    final private String ident;
    33    
     40
    3441    /**
    3542     * The (file-)path where the data will be stored
    3643     */
    3744    final private File path;
    38    
     45
    3946    /**
    4047     * How often to update the cached version
    4148     */
    4249    final private int updateInterval;
    43    
     50
    4451    /**
    4552     * This function will be executed when an update is required. It has to be implemented by the
     
    4956     */
    5057    protected abstract byte[] updateData();
    51    
     58
    5259    /**
    5360     * This function serves as a comfort hook to perform additional checks if the cache is valid
     
    5663    protected boolean isCacheValid() {
    5764        return true;
    58     }   
    59    
     65    }
     66
    6067    /**
    6168     * Initializes the class. Note that all read data will be stored in memory until it is flushed
    62      * by flushData(). 
     69     * by flushData().
    6370     * @param ident
    6471     * @param updateInterval
     
    6976        this.path = new File(Main.pref.getPreferencesDir(), ident);
    7077    }
    71    
     78
    7279    /**
    7380     * Updates data if required
     
    8087        return getData();
    8188    }
    82    
     89
    8390    /**
    8491     * Updates data if required
     
    9198        return getDataString();
    9299    }
    93    
     100
    94101    /**
    95102     * Executes an update regardless of updateInterval
     
    102109        return data;
    103110    }
    104    
     111
    105112    /**
    106113     * Executes an update regardless of updateInterval
     
    121128        return data;
    122129    }
    123    
     130
    124131    /**
    125132     * Returns the data without performing any updates
     
    131138
    132139    /**
    133      * Tries to load the data using the given ident from disk. If this fails, data will be updated 
     140     * Tries to load the data using the given ident from disk. If this fails, data will be updated
    134141     */
    135142    private void loadFromDisk() {
     
    143150        }
    144151    }
    145    
     152
    146153    /**
    147154     * Stores the data to disk
     
    154161            output.close();
    155162        } catch(Exception e) {}
    156     }       
    157    
     163    }
     164
    158165    /**
    159166     * Flushes the data from memory. Class automatically reloads it from disk or updateData() if
Note: See TracChangeset for help on using the changeset viewer.