Created
October 2, 2018 18:13
-
-
Save kocisov/5600a653c0b4fe84b045c69d5a7e1fcf to your computer and use it in GitHub Desktop.
Revisions
-
kocisov created this gist
Oct 2, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ // main process then const { app } = require('electron') const fs = require('fs') const directory = app.getPath('home') // /home folder on OS X const cacheDirectory = `${directory}/twitch-bot-cache` // /home/twitch-bot-cache/ const cacheDataFile = `${cacheDirectory}/data.json` // /home/twitch-bot-cache/data.json // "cached now" object let caches = {} // if cacheDirectory isn't available, we create it if (fs.existsSync(cacheDirectory) === false) { fs.mkdirSync(cacheDirectory) } // fsCache object, contains functions, etc. export const fsCache = { key(name, value) { // example: fsCache.key('button', 'is green'), fsCache.key('super_button', { is: 'green' }) caches[name] = value // rewrites cache file with new data fs.writeFileSync(cacheDataFile, JSON.stringify(caches, null, 2)) } } export function readFromCache(file, callback) { try { // read cache file const cacheContent = fs.readFileSync( `${cacheDirectory}/${file}.json`, 'utf-8' ) // run callback with file content (cached data, etc.) callback(cacheContent) } catch (err) { console.log('Error in Cache:', err) } }