-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
43230e0
commit d2aa73f
Showing
2 changed files
with
69 additions
and
56 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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 characters
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; | ||
} | ||
}; |