diff --git a/services/spelling/.gitignore b/services/spelling/.gitignore index 6a7109dc73..b0356cac1c 100644 --- a/services/spelling/.gitignore +++ b/services/spelling/.gitignore @@ -5,3 +5,4 @@ app.js test/UnitTests/js/* node_modules/* test/unit/js/ +cache/spell.cache \ No newline at end of file diff --git a/services/spelling/app/coffee/ASpell.coffee b/services/spelling/app/coffee/ASpell.coffee index 1bee5ae3cd..d6f9ae1248 100644 --- a/services/spelling/app/coffee/ASpell.coffee +++ b/services/spelling/app/coffee/ASpell.coffee @@ -3,27 +3,32 @@ ASpellWorkerPool = require "./ASpellWorkerPool" LRU = require "lru-cache" logger = require 'logger-sharelatex' fs = require 'fs' +settings = require("settings-sharelatex") +Path = require("path") cache = LRU(10000) OneMinute = 60 * 1000 +cacheFsPath = Path.resolve(settings.cacheDir, "spell.cache") +cacheFsPathTmp = cacheFsPath + ".tmp" + # load any existing cache try - oldCache = fs.readFileSync "spell.cache" + oldCache = fs.readFileSync cacheFsPath cache.load JSON.parse(oldCache) catch err - logger.log {err}, "could not load cache file" + logger.log err:err, cacheFsPath:cacheFsPath, "could not load the cache file" # write the cache every 30 minutes setInterval () -> dump = JSON.stringify cache.dump() - fs.writeFile "spell.cache.tmp", dump, (err) -> + fs.writeFile cacheFsPathTmp, dump, (err) -> if err? logger.log {err}, "error writing cache file" - fs.unlink "spell.cache.tmp" + fs.unlink cacheFsPathTmp else - fs.rename "spell.cache.tmp", "spell.cache" - logger.log {len: dump.length}, "wrote cache file" + fs.rename cacheFsPathTmp, cacheFsPath + logger.log {len: dump.length, cacheFsPath:cacheFsPath}, "wrote cache file" , 30 * OneMinute class ASpellRunner diff --git a/services/spelling/cache/.gitignore b/services/spelling/cache/.gitignore new file mode 100644 index 0000000000..945c9b46d6 --- /dev/null +++ b/services/spelling/cache/.gitignore @@ -0,0 +1 @@ +. \ No newline at end of file diff --git a/services/spelling/config/settings.defaults.coffee b/services/spelling/config/settings.defaults.coffee index 474be9da88..ab13f5429f 100644 --- a/services/spelling/config/settings.defaults.coffee +++ b/services/spelling/config/settings.defaults.coffee @@ -1,3 +1,5 @@ +Path = require('path') + module.exports = Settings = internal: spelling: @@ -12,5 +14,7 @@ module.exports = Settings = mongo: url : 'mongodb://127.0.0.1/sharelatex' + cacheDir: Path.resolve "cache" + healthCheckUserId: "53c64d2fd68c8d000010bb5f" \ No newline at end of file