common/corpus-common-addon/addon/utils/store.js
author ymh <ymh.work@gmail.com>
Sat, 07 May 2016 10:06:26 +0200
changeset 158 366509ae2f37
parent 127 5cd8c3065c38
child 182 1bcc373adabb
permissions -rw-r--r--
Add controller for themes count + upgrade ember for app-client

import store from 'store';
import * as constants from 'corpus-common-addon/utils/constants';

export default {
    set: function(key, val, exp) {
        var expiration = exp;
        if(typeof exp === 'undefined') {
          expiration = constants.DEFAULT_STORE_EXP;
        }
        store.set(key, { val:val, exp:expiration, time:new Date().getTime() });
        return val;
    },
    get: function(key) {
        var info = store.get(key)
        if (!info) { return null }
        if (new Date().getTime() - info.time > info.exp) { return null }
        return info.val
    }
}