/// <summary>
 /// Creates a new FileSystemTileCache.
 /// <para>
 /// Use the {@code persistent} argument to specify whether cache contents should be kept across instances. A
 /// persistent cache will serve any tiles it finds in {@code cacheDirectory}. Calling <seealso cref="#destroy()"/> on a
 /// persistent cache will not delete the cache directory. Conversely, a non-persistent cache will serve only tiles
 /// added to it via the <seealso cref="#put(Job, TileBitmap)"/> method, and calling <seealso cref="#destroy()"/> on a non-persistent
 /// cache will delete {@code cacheDirectory}.
 ///
 /// </para>
 /// </summary>
 /// <param name="capacity">
 ///            the maximum number of entries in this cache. </param>
 /// <param name="cacheDirectory">
 ///            the directory where cached tiles will be stored. </param>
 /// <param name="graphicFactory">
 ///            the graphicFactory implementation to use. </param>
 /// <param name="persistent">
 ///            if cache data will be kept between instances </param>
 /// <exception cref="IllegalArgumentException">
 ///             if the capacity is negative. </exception>
 /// <exception cref="IllegalArgumentException">
 ///             if the capacity is negative. </exception>
 public FileSystemTileCache(int capacity, IFolder cacheDirectory, IGraphicFactory graphicFactory, bool persistent)
 {
     this.observable = new Observable();
     this.persistent = persistent;
     this.lruCache   = new FileWorkingSetCache <string>(capacity);
     //this.@lock = new ReentrantReadWriteLock();
     if (IsValidCacheDirectory(cacheDirectory))
     {
         this.cacheDirectory = cacheDirectory;
         if (this.persistent)
         {
             // this will start a new thread to read in the cache directory.
             // there is the potential that files will be recreated because they
             // are not yet in the cache, but this will not cause any corruption.
             Task.Run(() => (new CacheDirectoryReader(this)).Run());
         }
     }
     else
     {
         this.cacheDirectory = null;
     }
     this.graphicFactory = graphicFactory;
 }
Esempio n. 2
0
 /// <param name="capacity">
 ///            the maximum number of entries in this cache. </param>
 /// <exception cref="IllegalArgumentException">
 ///             if the capacity is negative. </exception>
 public InMemoryTileCache(int capacity)
 {
     this.lruCache   = new BitmapLRUCache(capacity);
     this.observable = new Observable();
 }