etag-cache-leveldb
TypeScript icon, indicating that this package has built-in type declarations

2.1.1 • Public • Published

npm License Typed with TypeScript bundlejs downloads GitHub Issues Build Status Styled with prettier Commitizen friendly Known Vulnerabilities Coverage Status

etag-cache-leveldb

etag cache based on leveldb

example

import levelup from "levelup";
import leveldown from "leveldown";
import { ETagCacheLevelDB } from "etag-cache-leveldb";

const someDirectory = "/tmp";
const db = await levelup(leveldown(someDirectory));
const cache = new ETagCacheLevelDB(db);

const url = "https://api.github.com/";

const response = await fetch(url);

await cache.storeResponse(response);

// later

const headers = {};

await cache.addHeaders(url, headers); // fill in etag header

const responseWithETag = await fetch(url, { headers });
const cachedResponse = await cache.loadResponse(responseWithETag);

API

Table of Contents

ETagCacheLevelDB

Stores etags and bodies into leveldb. Reconstructs response with body if etag or url matches. Will store in the cache: url : etag etag : body

Parameters

  • db
  • options

addHeaders

Adds the "If-None-Match" header if etag is found for the url.

Parameters

Returns Promise<boolean> true if etag was found in cache and header has been added

statistics

Deliver statisics data.

Returns Object

storeResponse

Stores response in the cache. Two entries are stored:

  • url : etag
  • etag : body

Parameters

  • response Response as produced by fetch

Returns Promise<any>

loadResponse

Constructs a new Response feed from the cache if a matching etag is found in the cache.

Parameters

  • response Response as provided by fetch

Returns Promise<Response>

rawTagData

Strips away etag flags (weak and the like)

Parameters

Returns (string | undefined) raw etag

Package Sidebar

Install

npm i etag-cache-leveldb

Weekly Downloads

214

Version

2.1.1

License

BSD-2-Clause

Unpacked Size

12.7 kB

Total Files

5

Last publish

Collaborators

  • arlac77