一些在前後端用來進行儲存數據的地方或者方式

一些在前後端用來進行儲存數據的地方或者方式

文件: 可以通過生成新文件的方式將新數據進行儲存,這裏要考慮到對文件的讀寫,容量,操作繁瑣等等

數據庫: 屬於後端儲存數據的地方,如果前端去拿數據的話需要發送HTTP請求

緩存: 也叫cache memory即緩存內存,就是說是內存的一部分。屬於後端。google看一些文檔解釋如**cache memory** is a storage unit that stores copies of data from frequently used main**memory** locations so that the CPU can access that data faster,所以說一般這個是指備份,然後方便快讀多寫,但是會消耗CPU

內存:也叫virtual memory,內存的一部分。屬於後端。google看一些文檔解釋如**virtual memory is a memory management technique that allows the user to execute programs larger than the actual main memory.**這是一門內存管理技術,允許用戶執行比實際主要內存更大的程序。

Local StorageWeb storage API。屬於前端。查mdn文檔可以看到這個是Window.localStorage。看一下英文介紹

The read-only localStorage property allows you to access a Storage object for the Document's origin; the stored data is saved across browser sessions. localStorage is similar to sessionStorage, except that while data stored in localStorage has no expiration time, data stored in sessionStorage gets cleared when the page session ends — that is, when the page is closed.

It should be noted that data stored in either localStorage or sessionStorage is specific to the protocol of the page.

The keys and the values are always strings (note that, as with objects, integer keys will be automatically converted to strings).

首先這是儲存在瀏覽器這邊的,是前端部分。儲存在本地儲存的數據沒有過期時間。即相對於頁面的session會話結束,即頁面關閉時,這個數據會被清除;本地儲存不會清除。

Session StorageWeb storage API。屬於前端。 查mdn文檔,介紹

The sessionStorage property allows you to access a session Storage object for the current origin. sessionStorage is similar to localStorage; the only difference is while data stored in localStorage has no expiration time, data stored in sessionStorage gets cleared when the page session ends. A page session lasts for as long as the browser is open and survives over page reloads and restores.

Opening a page in a new tab or window causes a new session to be initiated with the value of the top-level browsing context, which differs from how session cookies work. Opening multiple tabs or Windows on the same URL creates sessionStorage for each tab or Window. Closing a tab or Window ends the session and the objects in sessionStorage are cleared as soon as the tab or Window is closed.

首先這是儲存在瀏覽器這邊的,是前端部分。只要瀏覽器是打開的,那麼這個頁面會話就會持續,並且存活下從頁面重新加載reloads和恢復restores。在一個新標籤或一個新的窗口打開一個頁面,一個新的會話就會被初始化,伴隨着最高級瀏覽環境的值,這個和會話cookies信息處理程序如何運作還是不同的。

Cookie: 參考mdn文檔HTTP cookies。前後端都可以用。

An HTTP cookie (web cookie, browser cookie) is a small piece of data that a server sends to the user's web browser. The browser may store it and send it back with the next request to the same server. Typically, it's used to tell if two requests came from the same browser — keeping a user logged-in, for example. It remembers stateful information for the stateless HTTP protocol.

主要是服務器發送給客戶端。

IndexedDB API: 參考mdn文檔

IndexedDB is a low-level API for client-side storage of significant amounts of structured data, including files/blobs. This API uses indexes to enable high-performance searches of this data. While Web Storage is useful for storing smaller amounts of data, it is less useful for storing larger amounts of structured data. IndexedDB provides a solution. This is the main landing page for MDN's IndexedDB coverage — here we provide links to the full API reference and usage guides, browser support details, and some explanation of key concepts.

相對於Web Storage,這個主要是儲存大量的結構化數據。

參考

Local Storage vs Session Storage vs Cookie

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章