New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@nexssp/cache

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nexssp/cache

Cache, cache json with JS functions..

  • 2.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@nexssp/cache

  • Just EASY basic caching..

Check how old cache is with: 2 days, 1d, 5m, 2y, 3.5 hrs, 1s. See below for examples.

// Example config.js - setup 2 caches. Nothing is done yet.
const cache = require('@nexssp/cache')
const os = require('os')

const cache1 = cache({
  bucket: 'languages',
  cachePath: os.tmpdir(),
  recreateCache: process.argv.includes('--nocache'),
  auto: true, // It will create directory if does not exist.
})

const cache2 = cache({
  recreateCache: process.argv.includes('--nocache'),
})

module.exports = { cache1, cache2 }
const cache = require('@nexssp/cache')
const cache1 = cache({ auto: true })
// program.js - they will only be initialised after cache.start()
// cache.start() returns the path to the cache
const cachePath = cache1.start()

// Write Object as JSON. keep in mind that this cache will save functions if you have them in your object!
cache.writeJSON('mycache.json', { a: 1, b: 2, c3: 3 })

// check if cache is not older then 1day)
// true means that it will return the cache content with the exists method, otherwise true/false
let cacheContent
if ((cacheContent = cache.exists(cacheTestFile, '1d', true))) {
  // ok we use cache content: cacheContent
}

// Or without true will only check
if (cache.exists(cacheTestFile, '1d')) {
  // ok cache exists and is notread yet
  const cacheContent = cache.read(cacheTestFile)

  // or JSON directly to the object
  const test = cache.readJSON(cacheTestFile)
}

cache.write('my new cache standard file', 'Just standard file.. no JSON')

cache.writeJSON('my new cache standard file', { x: 1, y: 2 })

Keywords

FAQs

Package last updated on 29 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc