-
Notifications
You must be signed in to change notification settings - Fork 430
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Revert "Move cache snapshot loading to Visit#start() (#1056)" This reverts commit e07639f. * Revert "Fix back navigation after POST form submission (#1014)" This reverts commit c207f5b. * Revert "Add disk cache store (#949)" This reverts commit f86a376. * Remove redudant test prefix * Bring back test Orginally added by @jayohms in 60cfbee
- Loading branch information
Alberto Fernández-Capel
authored
Nov 13, 2023
1 parent
e07639f
commit 675d626
Showing
16 changed files
with
85 additions
and
312 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,56 @@ | ||
import { DiskStore } from "./cache_stores/disk_store" | ||
import { MemoryStore } from "./cache_stores/memory_store" | ||
import { toCacheKey } from "../url" | ||
|
||
export class SnapshotCache { | ||
static currentStore = new MemoryStore(10) | ||
|
||
static setStore(storeName) { | ||
switch (storeName) { | ||
case "memory": | ||
SnapshotCache.currentStore = new MemoryStore(10) | ||
break | ||
case "disk": | ||
SnapshotCache.currentStore = new DiskStore() | ||
break | ||
default: | ||
throw new Error(`Invalid store name: ${storeName}`) | ||
} | ||
keys = [] | ||
snapshots = {} | ||
|
||
constructor(size) { | ||
this.size = size | ||
} | ||
|
||
has(location) { | ||
return SnapshotCache.currentStore.has(location) | ||
return toCacheKey(location) in this.snapshots | ||
} | ||
|
||
get(location) { | ||
return SnapshotCache.currentStore.get(location) | ||
if (this.has(location)) { | ||
const snapshot = this.read(location) | ||
this.touch(location) | ||
return snapshot | ||
} | ||
} | ||
|
||
put(location, snapshot) { | ||
return SnapshotCache.currentStore.put(location, snapshot) | ||
this.write(location, snapshot) | ||
this.touch(location) | ||
return snapshot | ||
} | ||
|
||
clear() { | ||
return SnapshotCache.currentStore.clear() | ||
this.snapshots = {} | ||
} | ||
|
||
// Private | ||
|
||
read(location) { | ||
return this.snapshots[toCacheKey(location)] | ||
} | ||
|
||
write(location, snapshot) { | ||
this.snapshots[toCacheKey(location)] = snapshot | ||
} | ||
|
||
touch(location) { | ||
const key = toCacheKey(location) | ||
const index = this.keys.indexOf(key) | ||
if (index > -1) this.keys.splice(index, 1) | ||
this.keys.unshift(key) | ||
this.trim() | ||
} | ||
|
||
trim() { | ||
for (const key of this.keys.splice(this.size)) { | ||
delete this.snapshots[key] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.