Skip to content

Commit f4665ca

Browse files
committed
merged with master
1 parent 2d459c2 commit f4665ca

File tree

2 files changed

+40
-85
lines changed

2 files changed

+40
-85
lines changed

resources.js

Lines changed: 29 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -89,53 +89,54 @@ export class ExamplePageCache extends PageCache {
8989

9090
/********************************************************************************************************** */
9191

92+
/*
9293
93-
// A class used to update the cache for a specific page
94-
// export class PageCacheResource extends PageCache {
94+
A class used to update the cache for a specific page
95+
export class PageCacheResource extends PageCache {
9596
96-
// // Invalidate the cache if necessary
97-
// invalidate() {
98-
// super.invalidate();
99-
// }
97+
// Invalidate the cache if necessary
98+
invalidate() {
99+
super.invalidate();
100+
}
100101
101-
// // Fetch the page and update the cache
102-
// async get() {
103-
// try {
104-
// const pageURL = ``; // URL of the page to cache
105-
// const cacheId = `pageURL/ + ${this.getId()}`; // Get the ID of the page to cache (to be implemented by the user)
102+
// Fetch the page and update the cache
103+
async get() {
104+
try {
105+
const pageURL = ``; // URL of the page to cache
106+
const cacheId = `pageURL/ + ${this.getId()}`; // Get the ID of the page to cache (to be implemented by the user)
106107
107-
// // Fetch the page content
108-
// const response = await fetch(pageURL);
108+
// Fetch the page content
109+
const response = await fetch(pageURL);
109110
110-
// if (!response.ok) {
111-
// throw new Error(`Failed to fetch the page: ${response.status}`);
112-
// }
111+
if (!response.ok) {
112+
throw new Error(`Failed to fetch the page: ${response.status}`);
113+
}
113114
114-
// // Convert the HTML content to string
115-
// const htmlContent = await response.text();
115+
// Convert the HTML content to string
116+
const htmlContent = await response.text();
116117
117-
// // Return the cached data in a structured format
118-
// return { id: cacheId, cachedData: htmlContent };
118+
// Return the cached data in a structured format
119+
return { id: cacheId, cachedData: htmlContent };
119120
120-
// } catch (e) {
121-
// console.log("CACHING ERROR:", e);
122-
// }
123-
// }
124-
// }
121+
} catch (e) {
122+
console.log("CACHING ERROR:", e);
123+
}
124+
}
125+
}
125126
126127
// Define PageCacheResource as the cache source
127-
//PageCache.sourcedFrom(PageCacheResource);
128+
PageCache.sourcedFrom(PageCacheResource);
129+
*/
128130

129131
/*
130132
Usage Instructions:
131133
132-
1. Implement the `getId()` method to define how cache IDs are generated.
134+
1. define the cache IDs.
133135
2. Customize `pageURL` based on where the page is hosted.
134136
3. Call this URL to access the cached content:
135137
http://localhost:9926/PageCacheResource/{yourCacheId}
136138
137139
Example:
138-
- Define your own logic for `getId()` to uniquely identify pages.
139140
- The returned `cachedData` will contain the HTML as a string.
140141
*/
141142

@@ -177,56 +178,3 @@ PageCache.sourcedFrom(PageCacheResource);
177178
//http://localhost:9926/PageCache/<cacheId>
178179

179180

180-
181-
182-
// TODO: need to create a README.md file with instructions on how to implement partial page caching
183-
184-
185-
186-
// TODO: EXTRA
187-
188-
189-
190-
191-
192-
//export class PageCache extends tables.PageCache {
193-
// get() {
194-
// return this.html;
195-
// }
196-
197-
198-
// export class PageCache extends tables.PageCache {
199-
// get() {
200-
// return { // can also return a full response header
201-
// status: 200,
202-
// headers: { 'Content-Type': 'text/html' },
203-
// body: this.html
204-
// }
205-
// }
206-
// }
207-
208-
209-
210-
// http://host.com/PageCache/testPage.html
211-
212-
213-
214-
// Put some thought into
215-
216-
// Naming component based on the the functionality of the component
217-
218-
219-
// fumctionality intent behind each component
220-
221-
// extenstion
222-
223-
224-
// TODO:
225-
226-
// What distinguishes each component from the other
227-
228-
229-
// intent of use vs functionality of a component
230-
231-
232-

schema.graphql

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@
55

66
# This will be the table where users can store their pages they would like to cache
77
# Keep this table simple
8-
type PageCache @table(expiration: 3600) @export{
9-
cacheControl: String # save cache control headers
10-
id: ID @primaryKey # Note ID should path to webpage url you are caching (e.g in https://www.birkenstock.com/us/men/ the id should be /us/men/ ) This is our primary key Key
11-
cachedData: String # cachedData should be the html of the webpage you are caching stored as a string
8+
type PageCache @table(expiration: 3600) @export {
9+
cacheControl: String
10+
# Stores the Cache-Control headers for the page, which dictate how caching should be handled (e.g., max-age, no-cache).
1211

12+
id: ID @primaryKey
13+
# The primary key representing the URL path of the cached webpage.
14+
# Example: For the URL https://www.birkenstock.com/us/men/, the `id` should be "/us/men/".
15+
# This allows us to uniquely identify cached pages based on their path.
16+
17+
cachedData: String
18+
# Stores the full HTML of the cached webpage as a string.
19+
# This is the rendered content that will be served from cache on subsequent requests.
1320
}
1421

0 commit comments

Comments
 (0)