GithubHelp home page GithubHelp logo

wal33d / cache_fetch-js Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 8 KB

Effortlessly manage API data with this flexible caching class. Auto-update, built-in cache expiration, and simple interface optimize data processing for all projects.

JavaScript 100.00%

cache_fetch-js's Introduction

Data Caching Class

A class for caching data from API requests in Node.js. This class makes use of the fs and fetch modules to store and retrieve data, respectively. The cached data is saved to a JSON file, and the class will automatically check the cache's expiration time and refresh the data as necessary.

Features

  • Automatically refreshes data when cache has expired
  • Uses fs module to save and load cache data
  • Throws an error if no token is provided

Usage

The class can be imported and instantiated in your Node.js code as follows:

const Data = require('./data');  
const data = new Data();

The Data class has the following methods:

autoUpdate(token, minutes = 1)

Starts the auto-update process, which checks the cache every minutes interval.

  • token (required): API token for making requests
  • minutes (optional, default 1): interval in minutes to check cache, default is 1
update(token)

Updates the cache on call with new data, bypassing the cacheExpiry Timer.

  • token (required): API token for making requests
getData(token)

Gets the data and updates the cache if necessary.

  • token (required): API token for making requests

Example

Here is a complete example of how to use the Data class:

const Data = require('./data'); 
const data = new Data(); 
const token = 'your_api_token';  

// Get the data 
data.getData(token).then((data) => { console.log(data); });`

cache_fetch-js's People

Contributors

wal33d avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.