Garrett Johnson 5 лет назад
Родитель
Сommit
cec655138b
3 измененных файлов с 10 добавлено и 5 удалено
  1. 2 1
      src/base/TilesRendererBase.js
  2. 6 3
      src/utilities/LRUCache.js
  3. 2 1
      test/LRUCache.test.js

+ 2 - 1
src/base/TilesRendererBase.js

@@ -44,6 +44,7 @@ export class TilesRendererBase {
 		this.fetchOptions = {};
 
 		this.lruCache = new LRUCache();
+		this.lruCache.sortCallback = lruSort;
 		this.downloadQueue = new PriorityQueue( 4 );
 		this.parseQueue = new PriorityQueue( 1 );
 		this.stats = {
@@ -107,7 +108,7 @@ export class TilesRendererBase {
 		toggleTiles( root, this );
 
 		// TODO: We may want to add this function in the requestTileContents function
-		lruCache.scheduleUnload( lruSort );
+		lruCache.scheduleUnload();
 
 	}
 

+ 6 - 3
src/utilities/LRUCache.js

@@ -22,6 +22,8 @@ class LRUCache {
 		this.itemList = [];
 		this.callbacks = new Map();
 
+		this.sortCallback = null;
+
 	}
 
 	// Returns whether or not the cache has reached the maximum size
@@ -107,7 +109,7 @@ class LRUCache {
 
 	// TODO: this should be renamed because it's not necessarily unloading all unused content
 	// Maybe call it "cleanup" or "unloadToMinSize"
-	unloadUnusedContent( prioritySortCb = null ) {
+	unloadUnusedContent() {
 
 		const unloadPercent = this.unloadPercent;
 		const targetSize = this.minSize;
@@ -117,6 +119,7 @@ class LRUCache {
 		const callbacks = this.callbacks;
 		const unused = itemList.length - usedSet.size;
 		const excess = itemList.length - targetSize;
+		const prioritySortCb = this.sortCallback;
 
 		if ( excess > 0 && unused > 0 ) {
 
@@ -169,7 +172,7 @@ class LRUCache {
 
 	}
 
-	scheduleUnload( prioritySortCb = null, markAllUnused = true ) {
+	scheduleUnload( markAllUnused = true ) {
 
 		if ( ! this.scheduled ) {
 
@@ -177,7 +180,7 @@ class LRUCache {
 			enqueueMicrotask( () => {
 
 				this.scheduled = false;
-				this.unloadUnusedContent( prioritySortCb );
+				this.unloadUnusedContent();
 				if ( markAllUnused ) {
 
 					this.markAllUnused();

+ 2 - 1
test/LRUCache.test.js

@@ -61,6 +61,7 @@ describe( 'LRUCache', () => {
 	it( 'should sort before unloading', () => {
 
 		const cache = new LRUCache();
+		cache.sortCallback = ( a, b ) => b.priority - a.priority;
 		cache.minSize = 0;
 		cache.maxSize = 10;
 		cache.unloadPercent = 1;
@@ -86,7 +87,7 @@ describe( 'LRUCache', () => {
 		cache.markUsed( P2 );
 		cache.markUsed( P3 );
 
-		cache.unloadUnusedContent( ( a, b ) => b.priority - a.priority );
+		cache.unloadUnusedContent();
 		expect( arr ).toEqual( [ 4, 1 ] );
 
 	} );