Permalink
Browse files

Replace whitespace tabs with spaces

  • Loading branch information...
1 parent 15f8b95 commit e42ff431f7500d756ab06c13874f69a87a3f02c9 @akaspin committed Jul 14, 2010
View
104 cache.js
@@ -14,42 +14,42 @@ var needFlush = [];
*
* @example
*
- * var sys = require("sys");
- * var cache = require("./cache");
+ * var sys = require("sys");
+ * var cache = require("./cache");
*
- * for (var i = 0; i < 100; i++) {
- * cache("key",
- * function(value){ // Getter
- * sys.debug("Getted: " + value);
- * },
- * function(callback){
- * setTimeout(function(){
- * sys.debug("Do render");
- * callback("test");
- * }, 2000);
- * }
- * );
- * }
+ * for (var i = 0; i < 100; i++) {
+ * cache("key",
+ * function(value){ // Getter
+ * sys.debug("Getted: " + value);
+ * },
+ * function(callback){
+ * setTimeout(function(){
+ * sys.debug("Do render");
+ * callback("test");
+ * }, 2000);
+ * }
+ * );
+ * }
*
* @param key Key in cache
* @param getter Function that fires if value for key is found.
- * Takes one argument - value from cache.
+ * Takes one argument - value from cache.
* @param setter Function that fires if value for key is not found.
- * Takes one argument - callback. Callback takes one argument too -
- * generated value.
+ * Takes one argument - callback. Callback takes one argument too -
+ * generated value.
*/
function operate(key, getter, setter) {
- if (key in cache) {
- getter(cache[key]);
- } else if (key in waiters) { // no cache look for waiters
- waiters[key].push(getter);
- } else { // no cache, no waiters - executing setter
- waiters[key] = [];
- waiters[key].push(getter);
- setter(function(value) {
- put(key, value);
- });
- }
+ if (key in cache) {
+ getter(cache[key]);
+ } else if (key in waiters) { // no cache look for waiters
+ waiters[key].push(getter);
+ } else { // no cache, no waiters - executing setter
+ waiters[key] = [];
+ waiters[key].push(getter);
+ setter(function(value) {
+ put(key, value);
+ });
+ }
}
exports.operate = operate;
@@ -59,32 +59,32 @@ exports.operate = operate;
* @param prefix Prefix of keys. If not defined - all cache will flushed.
*/
function flush(prefix) {
- prefix = (prefix || "");
-
- Object.keys(waiters).forEach(function(waiter) {
- if (waiter.indexOf(prefix) == 0) {
- needFlush.push(waiter);
- }
- });
- // delete all not locked keys in cache
- for (var key in cache) {
- if (key.indexOf(prefix) == 0 && needFlush.indexOf(key) == -1) {
- delete cache[key];
- }
- }
+ prefix = (prefix || "");
+
+ Object.keys(waiters).forEach(function(waiter) {
+ if (waiter.indexOf(prefix) == 0) {
+ needFlush.push(waiter);
+ }
+ });
+ // delete all not locked keys in cache
+ for (var key in cache) {
+ if (key.indexOf(prefix) == 0 && needFlush.indexOf(key) == -1) {
+ delete cache[key];
+ }
+ }
}
exports.flush = flush;
// private
function put(key, value) {
- cache[key] = value;
- waiters[key].forEach(function(action) {
- action(value);
- });
- delete waiters[key];
- var kill = needFlush.indexOf(key);
- if (kill != -1) {
- delete cache[key];
- needFlush.splice(kill, 1);
- }
+ cache[key] = value;
+ waiters[key].forEach(function(action) {
+ action(value);
+ });
+ delete waiters[key];
+ var kill = needFlush.indexOf(key);
+ if (kill != -1) {
+ delete cache[key];
+ needFlush.splice(kill, 1);
+ }
}
Oops, something went wrong.

0 comments on commit e42ff43

Please sign in to comment.