Skip to content

Instantly share code, notes, and snippets.

@arpitbbhayani
Created April 26, 2020 11:47
Show Gist options
  • Save arpitbbhayani/b7aa662eb51e16036c312a9cb1a9a812 to your computer and use it in GitHub Desktop.
Save arpitbbhayani/b7aa662eb51e16036c312a9cb1a9a812 to your computer and use it in GitHub Desktop.
def get_page(page_id:int) -> Page:
# Check if the page is available in the cache
page = cache.get_page(page_id)
# if the page is retrieved from the main memory
# return the page.
if page:
return page
# retrieve the page from the disk
page = disk.get_page(page_id)
# put the page in the cache,
# if the cache is full, evict a page which is
# least recently used.
if cache.is_full():
cache.evict_page()
# put the page in the cache
cache.put_page(page)
# return the pages
return page
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment