cache-storage
Version:
[ABANDONED] Advanced cache storage for node js
75 lines (47 loc) • 1.34 kB
text/coffeescript
Storage = require './Storage'
Cache = require '../../Cache'
fs = null
path = null
class FileStorage extends Storage
directory: null
allData: null
data: null
meta: null
constructor: () ->
if typeof window != 'undefined'
throw new Error 'FileStorage: Can not use this storage in browser'
fs = require 'fs'
path = require 'path'
= path.resolve()
if !Cache.getFs().existsSync()
throw new Error 'FileStorage: directory ' + + ' does not exists'
if !Cache.getFs().statSync().isDirectory()
throw new Error 'FileStorage: path ' + + ' must be directory'
getFileName: ->
return + '/__' + .namespace + '.json'
loadData: ->
if == null
file =
if Cache.getFs().existsSync(file)
= JSON.parse(Cache.getFs().readFileSync(file, encoding: 'utf8'))
else
= {data: {}, meta: {}}
return
getData: ->
if == null
= .data
return
getMeta: ->
if == null
= .meta
return
writeData: (, ) ->
=
data:
meta:
file =
Cache.getFs().writeFileSync(file, JSON.stringify(
data:
meta:
))
module.exports = FileStorage