Skip to content

Commit

Permalink
migrated cache (#946)
Browse files Browse the repository at this point in the history
  • Loading branch information
herrmannplatz authored Mar 27, 2017
1 parent 43230e0 commit d2aa73f
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 56 deletions.
56 changes: 0 additions & 56 deletions app/script/cache/CacheRepository.coffee

This file was deleted.

69 changes: 69 additions & 0 deletions app/script/cache/CacheRepository.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Wire
* Copyright (C) 2017 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
*/

'use strict';

window.z = window.z || {};
window.z.cache = z.cache || {};

/*
Cache repository for local storage interactions using amplify.
@todo We have to come up with a smart solution to handle "amplify.store quota exceeded"
This happened when doing "@cache_repository.set_entity user_et"
*/
z.cache.CacheRepository = class CacheRepository {
constructor() {
this.logger = new z.util.Logger('z.auth.CacheRepository', z.config.LOGGER.OPTIONS);
}

/*
Deletes cached data.
@param {Boolean} [keep_conversation_input=false] - Should conversation input be kept
@param {[Array<String>]} [protected_key_patterns=[z.storage.StorageKey.AUTH.SHOW_LOGIN]] - Keys which should NOT be deleted from the cache
@return [Array<String>] Keys which have been deleted from the cache
*/
clear_cache(keep_conversation_input = false, protected_key_patterns = [z.storage.StorageKey.AUTH.SHOW_LOGIN]) {
const deleted_keys = [];

if (keep_conversation_input) {
protected_key_patterns.push(z.storage.StorageKey.CONVERSATION.INPUT);
}

for (const stored_key in amplify.store()) {
let should_be_deleted = true;

for (const pattern in protected_key_patterns) {
if (stored_key.startsWith(protected_key_patterns[pattern])) {
should_be_deleted = false;
}
}

if (should_be_deleted) {
z.util.StorageUtil.reset_value(stored_key);
deleted_keys.push(stored_key);
}
}

return deleted_keys;
}
};

0 comments on commit d2aa73f

Please sign in to comment.