browser: add a cache
This commit is contained in:
parent
dd4a4196a8
commit
fef350804c
|
@ -31,6 +31,7 @@ class Browser:
|
||||||
self.status_data = ("", 0, 0)
|
self.status_data = ("", 0, 0)
|
||||||
self.current_url = ""
|
self.current_url = ""
|
||||||
self.history = History()
|
self.history = History()
|
||||||
|
self.cache = {}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def h(self):
|
def h(self):
|
||||||
|
@ -246,6 +247,15 @@ class Browser:
|
||||||
After initiating the connection, TODO
|
After initiating the connection, TODO
|
||||||
"""
|
"""
|
||||||
self.set_status(f"Loading {url}")
|
self.set_status(f"Loading {url}")
|
||||||
|
|
||||||
|
if url in self.cache:
|
||||||
|
self.load_page(self.cache[url])
|
||||||
|
if self.current_url and history:
|
||||||
|
self.history.push(self.current_url)
|
||||||
|
self.current_url = url
|
||||||
|
self.set_status(url)
|
||||||
|
return
|
||||||
|
|
||||||
req = Request(url, self.stash)
|
req = Request(url, self.stash)
|
||||||
connected = req.connect()
|
connected = req.connect()
|
||||||
if not connected:
|
if not connected:
|
||||||
|
@ -286,6 +296,7 @@ class Browser:
|
||||||
if self.current_url and history:
|
if self.current_url and history:
|
||||||
self.history.push(self.current_url)
|
self.history.push(self.current_url)
|
||||||
self.current_url = url
|
self.current_url = url
|
||||||
|
self.cache[url] = self.page_pad.current_page
|
||||||
self.set_status(url)
|
self.set_status(url)
|
||||||
elif handle_code == 1:
|
elif handle_code == 1:
|
||||||
self.set_status(f"Downloaded {url}.")
|
self.set_status(f"Downloaded {url}.")
|
||||||
|
|
Reference in a new issue