2016-07-15 58 views
0

enter image description heresailsjs不採摘的本地JSON更新

在這個sailsjs應用程序,我們沒有使用任何數據庫。數據文件夾中的文件夾中有多個json文件(您可以在根目錄中查看它)。 我們訪問像

req.session.categories = require(require('path').resolve('data/catInfo.json')); 

catInfo.json內部控制器通過一些cron作業每天更新兩次。問題是sailsjs沒有獲取更新的數據,但如果我重新啓動服務器,那麼它正在拾取新數據。它存儲舊json並服務那個老json。

我已經檢查:

1. try new browser/incognito browser. so this is not a session issue. 
2. data folder is not under assets folder. so it is not going under .tmp folder. 

然後在那裏被存儲在舊數據?

回答

1

包含在require中的模塊被緩存,這也意味着JSON文件。

如果文件正在更新,那麼您需要使用fs模塊讀取它。

req.session.categories = 
    JSON.parse(
     require('fs').readFileSync(require('path').resolve('data/catInfo.json')) 
    );