npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

s3-cached

v6.0.1

Published

S3 File Access Abstraction providing Memory and Disk Caching Layer

Downloads

411

Readme

Cached S3 Wrapper

Build Status Test Coverage Dependabot Status Dependencies NPM Downloads Semantic-Release Gardener

S3 File Access Abstraction providing Memory and Disk Caching Layer. Useful e.g. in lambda functions if you want to reduce the amount of s3 access for serving (semi-)static files.

What it does

  • Access abstraction to access JSON and GZipped data on AWS S3
  • Two Layer caching (memory and disk)
  • Allows you to define cache constraints like TTL

Getting Started

Install

$ npm install --save s3-cached

Request S3 Files

const s3 = require('s3-cached')({
  bucket: 'YOUR_BUCKET_NAME',
  awsSdkWrap: AwsSdkWrap(/* ... */)
});

s3.getJsonObjectCached('large.json').then((json) => {
  // do something with the json data
}).catch((err) => {
  // there has been an error
});

Available functions

  • getBinaryObjectCached: retrieve file content, caching additional modifications possible through parameter
  • getTextObjectCached: retrieve file content as string and return as promise
  • getJsonObjectCached: retrieve file content as string, parse as json and return as promise
  • getGzipObjectCached: retrieve file content, gunzip and return as promise
  • getKeysCached: retrieve all file names in bucket with given prefix

Note that you can specify the ttl and/or custom bucket on a per file basis by calling e.g. s3.getJsonObjectCached(FILE_NAME, { ttl, bucket }). For exact method signatures please check the code.

Other Function / Exports

  • resetCache(): Reset everything in cache
  • aws: The underlying aws-sdk-wrap instance

Options

bucket

Type: string Default: undefined

Specify the Bucket name you want to retrieve data from. It either has to be defined here or on every request (overwrites).

s3Options

Type: object Default: -

Passed into aws-wrap-sdk for AWS.S3() initialization.

logger

Type: logger Default: null

Passed into aws-wrap-sdk.

ttl

Type: integer Default: 600

Define how long a cached file is kept by default. This can be overwritten on a per-file basis by passing a second parameter into the function.

memoryLimit

Type: integer Default: 100

Define how many cached entities can be hold in memory at the same time. If more entities are present, the earliest are discarded from memory cache.

diskMaxSize

Type: integer Default: 469762048

Maximum amount of disk space in bytes used by disk cache. Earliest files are discarded from file cache if more space is used.

diskTmpDirectory

Type: string Default: /tmp

Location to store temporary data for disk cache.