mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
dump the cache every 30 minutes and load at startup
This commit is contained in:
parent
fdd9357a42
commit
8239bcd0b5
1 changed files with 21 additions and 0 deletions
|
@ -2,8 +2,29 @@ async = require "async"
|
|||
ASpellWorkerPool = require "./ASpellWorkerPool"
|
||||
LRU = require "lru-cache"
|
||||
logger = require 'logger-sharelatex'
|
||||
fs = require 'fs'
|
||||
|
||||
cache = LRU(10000)
|
||||
OneMinute = 60 * 1000
|
||||
|
||||
# load any existing cache
|
||||
try
|
||||
oldCache = fs.readFileSync "spell.cache"
|
||||
cache.load JSON.parse(oldCache)
|
||||
catch err
|
||||
logger.log {err}, "could not load cache file"
|
||||
|
||||
# write the cache every 30 minutes
|
||||
setInterval () ->
|
||||
dump = JSON.stringify cache.dump()
|
||||
fs.writeFile "spell.cache.tmp", dump, (err) ->
|
||||
if err?
|
||||
logger.log {err}, "error writing cache file"
|
||||
fs.unlink "spell.cache.tmp"
|
||||
else
|
||||
fs.rename "spell.cache.tmp", "spell.cache"
|
||||
logger.log {len: dump.length}, "wrote cache file"
|
||||
, 30 * OneMinute
|
||||
|
||||
class ASpellRunner
|
||||
checkWords: (language, words, callback = (error, result) ->) ->
|
||||
|
|
Loading…
Reference in a new issue