3.1.4 • Published 7 years ago

guard_dog v3.1.4

Weekly downloads
15
License
MIT
Repository
github
Last release
7 years ago

guard_dog

  • Data Persistence ( data will be saved in a .dog file as json )
  • Memory Cache ( guard_dog.get( ) )
  • Auto Timed Refresh ( handler( ) )

Installation

$ npm install guard_dog

Usage

guard_dog.init( key, loader, dir)

  • key < string, required > The key of data, the name of the .dog file.
  • loader < function, required > Will refresh this data by call this function when it needs.
  • dir < string, optional > The .dog file stored directory.

loader:

(handler) => {
    handler()
}

handler( data, expires_in, ahead )

  • data < string/object, required > Data need to store.
  • expires_in < integer, required > Unit is second, data only availability during this time.
  • ahead < integer, optional > Unit is second, defualt is 2s. It means guard_dog will refresh data 2s earlier before it expired by default.

Note: If (expires_in - ahead <= 0), it will never be refreshed.

guard_dog.init('KEY', (handler) => {
    handler(data, 3) // It will be refreshed every second
})

guard_dog.get( key, callback )

  • key < string, required > The key you pass when you call guard_dog.init()
  • callback < function, required > (data) => {}

Before calling this function, guard_dog.init() must be called.

guard_dog.get('KEY', (data) => {
    console.log(data)
})

Examples

3.1.4

7 years ago

3.1.3

7 years ago

3.1.2

7 years ago

3.1.1

7 years ago

3.1.0

7 years ago

3.0.0

7 years ago

2.1.0

7 years ago

2.0.0

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago