angular-local-storage
angular-local-storage copied to clipboard
Using a different storage type per module
From what I can tell, due to this module being a service, you can only set one storage type for entire application, not per module. Is this correct?
Use case
I have an application made up of 2 modules, where both are using the localStorageService
. One is trying to use sessionStorage
and the other localStorage
, but they are overriding each other.
@hollandben It's definitely something that we need to solve.
Cool. I'll try and get a PR together with an implementation as well. On 23 Oct 2014 19:19, "Ariel Mashraki" [email protected] wrote:
@hollandben https://github.com/hollandben It's definitely something that we need to solve. I'm gonna to work on that this weekend.
— Reply to this email directly or view it on GitHub https://github.com/grevory/angular-local-storage/issues/151#issuecomment-60284120 .
we should fix that, so we'll be able to do things like that:
angular.module('app', ['LocalStorageModule', 'sessionModule'])
.controller('MainCtrl', function($scope, localStorageService, sessionStorageService) {
//...
});
angular.module('sessionModule', ['LocalStorageModule'])
.config(function (localStorageServiceProvider) {
localStorageServiceProvider
.setStorageType('sessionStorage');
})
.factory('sessionStorageService', function(localStorageService) {
return localStorageService;
});
:+1:
:+1:
Are there already any updates on this? I have a similar issue where I want to use different prefixes for two modules which currently does not seem to be possible. So I would be really happy to see a fix here as well!
+1
+1 .... was investigating angular-local-storage and noticed this issue was a potential issue for me to just use it at the moment.
+1
+1
+1
+1
Could you make the call interface like these: get(key, storageType) set(key, value, storageType) and won't affect subsequent calls.
And since 'Allow creating multiple instances' and 'Use both sessionStorage and localStorage' redirect here, should issue title be updated to reflect that. Thank you.
+1
+1
+1
I think is done with #320, isn't it ?
hi @JR-Utily, it solves the problem partially. From what I can see it doesn't just use the specified storage type for that transaction, but actually changes it for all future transactions. Is this correct?
An example:
Lets say that my default storage type is localStorage
, I believe this will happen:
// Sets the status to be true in sessionStorage
localStorageService.set('status', true, 'sessionStorage');
// Sets the status to be false in sessionStorage
// I would expect this to inherit the default storage type
localStorageService.set('status', false);
I'll create an isolated test case to make sure this is/isn't happening, but from the PR you reference, it appears this is the case