jmdobry / angular-cache

angular-cache is a very useful replacement for the Angular 1 $cacheFactory.
http://jmdobry.github.io/angular-cache
MIT License
1.39k stars 156 forks source link

Allow service injection in storageImpl #198

Closed aaaaahaaaaa closed 9 years ago

aaaaahaaaaa commented 9 years ago

Hi,

It would be nice to have a way to inject another service to be used as a polyfill in 'storageImpl', like 'angular-local-storage' for instance. I woudn't really know actually how to do that, but I was thinking of something like the 'resolve' option you find with some Angular providers.

.config(function(CacheFactoryProvider) {
    angular.extend(CacheFactoryProvider.defaults, {
        maxAge: 60 * 60 * 1000,
        deleteOnExpire: 'aggressive',
        storageMode: 'localStorage',
        storageImpl: function(localStorageService) {
            return {
                getItem: localStorageService.get,
                setItem: localStorageService.set,
                removeItem:  localStorageService.remove
            };
        }
    });
})
aaaaahaaaaa commented 9 years ago

Hum, my comparison with 'resolve' probably doesn't make any sense actually. I guess my question is a general Angular question of how to inject a service in 'config' block...

jmdobry commented 9 years ago

http://stackoverflow.com/a/21650337


Closing because I’m not sure this is an issue, if you are convinced that this is really a bug, please feel free to re-open the issue and add more information:

Otherwise support is done via the mailing list.