The Internals of Deno
  • The Internals of Deno
  • Audience
  • Reviews
  • Translations
  • Formats
  • Contents
  • Chapter 1 - INTRODUCTION
    • 1.0 Cover page
    • 1.1 Introduction
    • 1.2 History of Deno
    • 1.3 About Deno
    • 1.4 Releases
    • 1.5 The Deno Company
    • 1.6 Deno's source
    • 1.7 What's next
  • Chapter 2 - ARCHITECTURE
    • 2.0 Cover page
    • 2.1 Architecture
    • 2.2 Overall architecture
    • 2.3 Programming Languages
    • 2.4 Deno components
    • 2.5 OPs
    • 2.6 TSC/SWC
    • 2.7 Rusty_v8
    • 2.8 Tokio
    • 2.9 V8
    • 2.10 What's next
  • CHAPTER 3 - THREADING MODEL
    • 3.0 Cover page
    • 3.1 Threading model
    • 3.2 Default threading model
    • 3.3 Asynchronous green threads
    • 3.4 What's next
  • CHAPTER 4 - BRIDGE
    • 4.0 Cover page
    • 4.1 The bridge
    • 4.2 Print
    • 4.3 Encode and decode
    • 4.4 What's next
  • CHAPTER 5 - FOUNDATIONS
    • 5.0 Cover page
    • 5.1 Hello world program
    • 5.2 Basic hello world
    • 5.3 Main program of Deno
    • 5.4 Module Specifier
    • 5.5 CLI Factory
    • 5.6 Permissions
    • 5.7 Main Worker
    • 5.8 JS Runtime
    • 5.9 Run main module
    • 5.10 Load module
    • 5.11 Recursive module loading
    • 5.12 Module graphs
    • 5.13 File fetching
    • 5.14 Transpile
    • 5.15 Register / compile module
    • 5.16 Instantiate module
    • 5.17 Evaluate module
    • 5.18 What's next
  • CHAPTER 6 - IMPORTS AND OPS
    • 6.0 Cover page
    • 6.1 Imports and ops
    • 6.2 Hello world program v2
    • 6.3 Module graph with imports
    • 6.4 Transpile
    • 6.5 Registration and instantiation
    • 6.6 Registration of ops
    • 6.7 Evaluate module
    • 6.8 Sync OPs
    • 6.9 Debug logs
    • 6.10 What's next
  • CHAPTER 7 - LOCAL AND SESSION STORAGE
    • 7.0 Cover page
    • 7.1 Introduction
    • 7.2 Local storage
    • 7.3 Session storage
    • 7.4 What's next
  • AFTERWORD
    • Afterword
Powered by GitBook
On this page
  1. CHAPTER 7 - LOCAL AND SESSION STORAGE

7.1 Introduction

Data persistence plays a crucial role in building robust Deno applications. Local storage and session storage, two built-in client-side storage options, empower developers to store and retrieve data, enhancing user experience and application functionality. Not limiting to browsers, these are also provided by Deno.

Local storage excels in storing data that persists across browser sessions (or Deno restarts), making it ideal for user preferences, settings, and persistent application state. Consider storing font size choices, preferred product categories, or frequently used shipping addresses—all accessible even after closing and reopening the webpage (or restarting Deno application).

Session storage, in contrast, offers a temporary home for data relevant only within a single browsing session (or a single run of Deno runtime). It's perfect for shopping cart contents, form data between page redirects, or other transient information that can safely vanish when the tab or window closes (or Deno stops).

Deno provides web standard APIs to interact with these storage mechanisms:

  • Setting Data:

    • localStorage.setItem(key, value) stores a key-value pair within local storage.

    • sessionStorage.setItem(key, value) stores a key-value pair within session storage.

  • Retrieving Data:

    • localStorage.getItem(key) retrieves the value associated with a specific key from local storage.

    • sessionStorage.getItem(key) retrieves the value associated with a specific key from session storage.

  • Removing Data:

    • localStorage.removeItem(key) deletes a key-value pair from local storage.

    • sessionStorage.removeItem(key) deletes a key-value pair from session storage.

  • Clearing All Data:

    • localStorage.clear() empties the entire local storage.

    • sessionStorage.clear() empties the entire session storage.

Some key considerations when working with these storage mechanisms are:

  • Both storage mechanisms are restricted to storing strings. To store objects or arrays, serialization techniques like JSON.stringify() and JSON.parse() are required.

  • Accessing local and session storage involves asynchronous operations, necessitating the use of Promises or async/await syntax for optimal handling.

In the two upcoming sections of this chapter, we'll learn:

  • 7.2 How local storage works in Deno 7.2 Local storage

  • 7.3 How session storage works in Deno 7.3 Session storage

Let's get started with the inner workings of local storage.

Previous7.0 Cover pageNext7.2 Local storage

Last updated 10 months ago