1 // This file is part of Moodle - http://moodle.org/
3 // Moodle is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
8 // Moodle is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 * Simple API for set/get to localstorage, with cacherev expiration.
19 * @module core/localstorage
21 * @copyright 2015 Damyon Wiese <damyon@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 define(['core/config', 'core/storagewrapper'], function(config, StorageWrapper) {
27 // Private functions and variables.
28 /** @var {Object} StorageWrapper - Wraps browsers localStorage object */
29 var storage = new StorageWrapper(window.localStorage);
31 return /** @alias module:core/localstorage */ {
33 * Get a value from local storage. Remember - all values must be strings.
36 * @param {string} key The cache key to check.
37 * @return {boolean|string} False if the value is not in the cache, or some other error - a string otherwise.
40 return storage.get(key);
44 * Set a value to local storage. Remember - all values must be strings.
47 * @param {string} key The cache key to set.
48 * @param {string} value The value to set.
49 * @return {boolean} False if the value can't be saved in the cache, or some other error - true otherwise.
51 set: function(key, value) {
52 return storage.set(key, value);