Skip to content

Commit

Permalink
Rename HTTP cache to browser cache
Browse files Browse the repository at this point in the history
To avoid confusion with the HTTP cache that acts automatically on HTTP
requests. This cache is in the browser, but needs to be manually handled.
  • Loading branch information
afcapel committed Jul 21, 2023
1 parent 74197c5 commit 5666de6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CacheStore } from "../cache_store"
import { PageSnapshot } from "../page_snapshot"

export class HttpCacheStore extends CacheStore {
export class BrowserCacheStore extends CacheStore {
_version = "v1"
storage!: Cache

Expand Down
6 changes: 3 additions & 3 deletions src/core/drive/snapshot_cache.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PageSnapshot } from "./page_snapshot"
import { CacheStore } from "./cache_store"
import { HttpCacheStore } from "./cache_stores/http_cache_store"
import { BrowserCacheStore } from "./cache_stores/browser_cache_store"
import { MemoryStore } from "./cache_stores/memory_store"

export class SnapshotCache {
Expand All @@ -11,8 +11,8 @@ export class SnapshotCache {
case "memory":
SnapshotCache.currentStore = new MemoryStore(10)
break
case "http-cache":
SnapshotCache.currentStore = new HttpCacheStore()
case "browser-cache":
SnapshotCache.currentStore = new BrowserCacheStore()
break
default:
throw new Error(`Invalid store name: ${storeName}`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<script src="/dist/turbo.es2017-umd.js" data-turbo-track="reload"></script>
<script src="/src/tests/fixtures/test.js"></script>
<script>
Turbo.cache.store = "http-cache"
Turbo.cache.store = "browser-cache"

document.addEventListener("turbo:load", async () => {
await new Promise(resolve => setTimeout(resolve, 100))
Expand All @@ -34,13 +34,13 @@ <h1>Cached pages:</h1>
<h3>Links:</h3>
<ul>
<li>
<a id="first-link" href="./http_cache.html">First HTTP cached page</a>
<a id="first-link" href="./browser_cache.html">First HTTP cached page</a>
</li>
<li>
<a id="second-link" href="./http_cache.html?page=2">Second HTTP cached page</a>
<a id="second-link" href="./browser_cache.html?page=2">Second HTTP cached page</a>
</li>
<li>
<a id="third-link" href="./http_cache.html?page=3">Third HTTP cached page</a>
<a id="third-link" href="./browser_cache.html?page=3">Third HTTP cached page</a>
</li>
</ul>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Page, test, expect } from "@playwright/test"
import { nextBody } from "../helpers/page"

const path = "/src/tests/fixtures/http_cache.html"
const path = "/src/tests/fixtures/browser_cache.html"

test.beforeEach(async ({ page }) => {
await page.goto(path)
Expand All @@ -13,30 +13,30 @@ test("test stores pages in the http cache", async ({ page }) => {
page.click("#second-link")
await nextBody(page)

await assertCachedURLs(page, ["http://localhost:9000/src/tests/fixtures/http_cache.html"])
await assertCachedURLs(page, ["http://localhost:9000/src/tests/fixtures/browser_cache.html"])

page.click("#third-link")
await nextBody(page)

await assertCachedURLs(page, [
"http://localhost:9000/src/tests/fixtures/http_cache.html",
"http://localhost:9000/src/tests/fixtures/http_cache.html?page=2",
"http://localhost:9000/src/tests/fixtures/browser_cache.html",
"http://localhost:9000/src/tests/fixtures/browser_cache.html?page=2",
])

// Cache persists across reloads
await page.reload()

await assertCachedURLs(page, [
"http://localhost:9000/src/tests/fixtures/http_cache.html",
"http://localhost:9000/src/tests/fixtures/http_cache.html?page=2",
"http://localhost:9000/src/tests/fixtures/browser_cache.html",
"http://localhost:9000/src/tests/fixtures/browser_cache.html?page=2",
])
})

test("can clear the http cache", async ({ page }) => {
page.click("#second-link")
await nextBody(page)

await assertCachedURLs(page, ["http://localhost:9000/src/tests/fixtures/http_cache.html"])
await assertCachedURLs(page, ["http://localhost:9000/src/tests/fixtures/browser_cache.html"])

page.click("#clear-cache")
await assertCachedURLs(page, [])
Expand Down

0 comments on commit 5666de6

Please sign in to comment.