File tree Expand file tree Collapse file tree 2 files changed +4
-49
lines changed Expand file tree Collapse file tree 2 files changed +4
-49
lines changed Original file line number Diff line number Diff line change @@ -49,53 +49,10 @@ Follow the comments in the code for guidance on how to set it up.
4949
5050
5151## Example
52-
53-
54-
55- Below is an example of how to define a custom ``` PageCacheResource ```
56-
57- Uncomment this code in the ``` resource.js ``` file
58-
59-
60- ``` javascript
61- export class ExamplePageCacheResource extends Resource {
62- // Invalidate cache if necessary
63- invalidate () {
64- super .invalidate ();
65- }
6652
67- // Fetch and cache the page
68- async get () {
69- try {
70- // Fetch the page content from an external source
71- const response = await fetch (` https://www.google.com/` );
72-
73- // Check if the response is successful (status code 200)
74- if (! response .ok ) {
75- throw new Error (` HTTP error! Status: ${ response .status } ` );
76- }
77-
78- // Convert the raw HTML response to a string
79- const rawHtmlToStr = await response .text ();
80-
81- // Return the cache data
82- return { id: " /testPage" , cachedData: rawHtmlToStr };
83-
84- } catch (error) {
85- // Log any errors that occur during the fetch process
86- console .error (" ERROR fetching page data:" , error);
87- }
88- }
89- }
90-
91- // Define this class as a cache source for PageCache
92- PageCache .sourcedFrom (ExamplePageCacheResource);
93-
94- ```
95-
96- Once the comments have been removed from this code visit the following URL in the browser to access the webpage cached.
97-
98- ``` http://localhost:9926/PageCache/testPage ```
53+ *** visit the following URL in the browser to access the webpage cached*** :
54+
55+ ``` http://localhost:9926/PageCache/examplePage ```
9956
10057
10158
Original file line number Diff line number Diff line change @@ -70,14 +70,12 @@ export class PageCacheResource extends PageCache {
7070 //convert html to string
7171 const convertHtmlTextToStr = await response . text ( ) ;
7272
73-
74-
7573 //Return the cached data in a structured format
7674 return { cachedData : convertHtmlTextToStr } ;
7775 }
7876}
7977
80- // you can access the cache from the browser using the following URL: http://localhost:9926/PageCache/<cacheId>(e.g. /examplePage)
78+ // you can access the cache from the browser using the following URL: http://localhost:9926/PageCache/<cacheId>
8179
8280// The ID is set using HarperDB REST handler
8381
You can’t perform that action at this time.
0 commit comments