Skip to content

Commit

Permalink
FIX: Use circular-json to handle circular references (fix #5)
Browse files Browse the repository at this point in the history
  • Loading branch information
nopnop committed Jul 25, 2016
1 parent 3a613fd commit cd7aeed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
9 changes: 6 additions & 3 deletions cache.js
@@ -1,8 +1,10 @@
var path = require( 'path' );
var fs = require( 'graceful-fs' );
var readJSON = require( 'read-json-sync' );
var write = require( 'write' );
var del = require( 'del' ).sync;
var circularJson = require( 'circular-json' );

var fileCache = { };

var cache = {
/**
Expand All @@ -22,7 +24,8 @@ var cache = {
me._pathToFile = cacheDir ? path.resolve( cacheDir, docId ) : path.resolve( __dirname, './.cache/', docId );

if ( fs.existsSync( me._pathToFile ) ) {
me._persisted = readJSON( me._pathToFile );
me._persisted = fileCache[ me._pathToFile ] || circularJson.parse( fs.readFileSync( me._pathToFile ).toString() );
fileCache[ me._pathToFile ] = me._persisted;
}
},

Expand Down Expand Up @@ -106,7 +109,7 @@ var cache = {
var me = this;

me._prune();
write.sync( me._pathToFile, JSON.stringify( me._persisted ) );
write.sync( me._pathToFile, circularJson.stringify( me._persisted ) );
},

/**
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -78,6 +78,7 @@
"watch-run": "^1.2.2"
},
"dependencies": {
"circular-json": "^0.3.0",
"del": "^2.0.2",
"graceful-fs": "^4.1.2",
"read-json-sync": "^1.1.0",
Expand Down

0 comments on commit cd7aeed

Please sign in to comment.