angular-local-storage icon indicating copy to clipboard operation
angular-local-storage copied to clipboard

Using a different storage type per module

Open benhoIIand opened this issue 10 years ago • 17 comments

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.

benhoIIand avatar Oct 21 '14 16:10 benhoIIand

@hollandben It's definitely something that we need to solve.

a8m avatar Oct 23 '14 18:10 a8m

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 .

benhoIIand avatar Oct 23 '14 18:10 benhoIIand

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;
  });

a8m avatar Oct 23 '14 18:10 a8m

:+1:

rvanbaalen avatar Nov 07 '14 13:11 rvanbaalen

:+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!

ctavan avatar Nov 24 '14 10:11 ctavan

+1

tua avatar Dec 09 '14 09:12 tua

+1 .... was investigating angular-local-storage and noticed this issue was a potential issue for me to just use it at the moment.

coreycochran89 avatar Feb 03 '15 19:02 coreycochran89

+1

StanleyGoldman avatar Mar 13 '15 15:03 StanleyGoldman

+1

fvelosa avatar Mar 14 '15 17:03 fvelosa

+1

ajorquera avatar Nov 29 '15 14:11 ajorquera

+1

kmaida avatar Mar 22 '16 20:03 kmaida

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.

zerowang avatar May 13 '16 05:05 zerowang

+1

ronnyle avatar Sep 26 '16 08:09 ronnyle

+1

thmarti avatar Nov 22 '16 17:11 thmarti

+1

alinearielo avatar Dec 28 '16 13:12 alinearielo

I think is done with #320, isn't it ?

JR-Utily avatar Jan 17 '17 10:01 JR-Utily

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

benhoIIand avatar Feb 02 '17 11:02 benhoIIand