Navigation Menu

Skip to content
This repository has been archived by the owner on Apr 18, 2020. It is now read-only.

Commit

Permalink
Releasing into the wilds.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason LaPorte committed Nov 20, 2012
1 parent 49cec11 commit aa11350
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
34 changes: 19 additions & 15 deletions README.md
@@ -1,21 +1,21 @@
Cache
=====
cache-helpers
=============

`cache` is a Node.JS module containing several generic caching functions. It
was written as a way of abstracting out a number of commonly used patterns in
the Dark Sky API.
`cache-helpers` is a Node.JS module containing several generic caching
functions. It was written as a way of abstracting out a number of commonly used
patterns in the [Dark Sky API](http://developer.darkskyapp.com/).

* `cache.once`: Takes a (presumably expensive) function which takes a single
callback and calls it with an optional error argument and a data argument.
It returns a function that you may use as a proxy for the passed function.
The first time it is called, it will call the function and cache it's data.
Subsequent calls will return the cached data.
* `cacheHelpers.once`: Takes a (presumably expensive) function which takes a
single callback and calls it with an optional error argument and a data
argument. It returns a function that you may use as a proxy for the passed
function. The first time it is called, it will call the function and cache
its data. Subsequent calls will return the cached data.

(It is smart enough to only call the backing function once even if it is
called many times simultaneously.)

* `cache.timeBasedWithGrace`: Takes a (presumably expensive) function, like
`once`, above, and two numbers: a soft cache timeout and a hard cache
* `cacheHelpers.timeBasedWithGrace`: Takes a (presumably expensive) function,
like `once`, above, and two numbers: a soft cache timeout and a hard cache
timeout. These timeouts may be in any arbitrary units you prefer, though
either seconds or milliseconds is most convenient. Like `once`, it returns
a proxy function, which is called with the current time (in whatever units
Expand All @@ -38,12 +38,16 @@ the Dark Sky API.
(Like `once`, this function is smart enough to not call the backing
function more often than necessary.)

* `cache.sizeBasedKeyValue`: Similar to the others. Takes a function and a
maximum cache size. The passed function is expected to take a key parameter
and a callback. The function returned by this method will take the same.
* `cacheHelpers.sizeBasedKeyValue`: Similar to the others. Takes a function
and a maximum cache size. The passed function is expected to take a key
parameter and a callback. The function returned by this method will take
the same.

If the cache gets full and a new item is requested, the least-recently-used
item is purged.

(Like the other functions, this function is also smart enough to not call
the backing function more often than necessary.)

These are kind of advanced, and may be fairly hard to understand without a
concrete use case. Checking out the tests may help.
10 changes: 5 additions & 5 deletions package.json
@@ -1,17 +1,17 @@
{
"name": "cache",
"version": "1.2.0",
"name": "cache-helpers",
"version": "1.3.0",
"description": "caching convenience functions",
"keywords": [
"caching"
],
"author": {
"name": "J.T.L.",
"email": "ironwallaby@gmail.com"
"name": "The Dark Sky Company",
"email": "devsupport@darkskyapp.com"
},
"repository": {
"type": "git",
"url": "git://github.com/ironwallaby/cache.git"
"url": "git://github.com/darkskyapp/cache-helpers.git"
},
"dependencies": {
},
Expand Down

0 comments on commit aa11350

Please sign in to comment.