Module 'angular-data.DSCacheFactory' is not available!

I am injecting a angular-cache module in my app! But I am getting this error.

Uncaught Error: [$injector:modulerr] Failed to instantiate module sociogram due to: Error: [$injector:modulerr] Failed to instantiate module angular-data.DSCacheFactory due to: Error: [$injector:nomod] Module 'angular-data.DSCacheFactory' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument. http://errors.angularjs.org/1.3.13/$injector/nomod?p0=angular-data.DSCacheFactory at REGEX_STRING_REGEXP (http://localhost:8100/lib/ionic/js/ionic.bundle.js:8755:12) at http://localhost:8100/lib/ionic/js/ionic.bundle.js:10459:17 at ensure (http://localhost:8100/lib/ionic/js/ionic.bundle.js:10383:38) at module (http://localhost:8100/lib/ionic/js/ionic.bundle.js:10457:14) at http://localhost:8100/lib/ionic/js/ionic.bundle.js:12789:22 at forEach (http://localhost:8100/lib/ionic/js/ionic.bundle.js:9015:20) at loadModules (http://localhost:8100/lib/ionic/js/ionic.bundle.js:12773:5) at http://localhost:8100/lib/ionic/js/ionic.bundle.js:12790:40 at forEach (http://localhost:8100/lib/ionic/js/ionic.bundle.js:9015:20) at loadModules (http://localhost:8100/lib/ionic/js/ionic.bundle.js:12773:5) http://errors.angularjs.org/1.3.13/$injector/modulerr?p0=angular-data.DSCac…%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A12773%3A5) at REGEX_STRING_REGEXP (http://localhost:8100/lib/ionic/js/ionic.bundle.js:8755:12) at http://localhost:8100/lib/ionic/js/ionic.bundle.js:12812:15 at forEach (http://localhost:8100/lib/ionic/js/ionic.bundle.js:9015:20) at loadModules (http://localhost:8100/lib/ionic/js/ionic.bundle.js:12773:5) at http://localhost:8100/lib/ionic/js/ionic.bundle.js:12790:40 at forEach (http://localhost:8100/lib/ionic/js/ionic.bundle.js:9015:20) at loadModules (http://localhost:8100/lib/ionic/js/ionic.bundle.js:12773:5) at createInjector (http://localhost:8100/lib/ionic/js/ionic.bundle.js:12699:11) at doBootstrap (http://localhost:8100/lib/ionic/js/ionic.bundle.js:10137:20) at bootstrap (http://localhost:8100/lib/ionic/js/ionic.bundle.js:10158:12) http://errors.angularjs.org/1.3.13/$injector/modulerr?p0=sociogram&p1=Error…3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A10158%3A12)

This is my code where i am injecting the module in my app:
index.html:

<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="lib/angular-cache/dist/angular-cache.min.js"></script>
<script src="js/ng-cordova.min.js"></script>
<script src="cordova.js"></script>

<script src="js/app.js"></script>
<script src="js/openfb-angular.js"></script>
<script src="js/controllers.js"></script>

app.js:

angular.module('sociogram', ['ionic','angular-data.DSCacheFactory', 'openfb', 'sociogram.controllers','ngCordova'])

    .run(function ($rootScope,DSCacheFactory, $state, $ionicPlatform, $window, OpenFB) {

        OpenFB.init('app_id','http://localhost:8100/oauthcallback.html');

        $ionicPlatform.ready(function () {
            if (window.StatusBar) {
                StatusBar.styleDefault();
            }
        });

        DSCacheFactory("leagueDataCache",{ storageMode: "localStorage", maxAge:10000, deleteOnExpire: "aggressive"});
        DSCacheFactory("leaguesCache",{ storageMode: "localStorage", maxAge:10000, deleteOnExpire: "aggressive"});
        DSCacheFactory("MyTeamsCache",{ storageMode: "localStorage"});
        DSCacheFactory("staticCache",{ storageMode: "localStorage"});

        $rootScope.$on('$stateChangeStart', function(event, toState) {
            if (toState.name !== "app.login" && toState.name !== "app.logout" && !$window.sessionStorage['fbtoken']) {
                $state.go('app.login');
                event.preventDefault();
            }
        });

        $rootScope.$on('OAuthException', function() {
            $state.go('app.login');
        });

    });

Please help! What is wrong with this code?

What is the name of the module to inject? ‘angular-data.DSCacheFactory’ or ‘DSCacheFactory’

What version of angular-cache do you use? If you use version 4.x.x see changelog:

DSCacheFactory renamed to CacheFactory

Check: https://github.com/jmdobry/angular-cache

1 Like

angular-cache version 4.1.0

Actually I am going through a tutorials on plural site about angular-cache in ionic! In that tutorial, “angular-data.DSCacheFactory” module used!

@fabioferrero Thank you! It not DSCacheFactory it is CacheFactory…:slight_smile:

I’ve been following the tutorial on pluralsight.com but the angular-cache version used in the tutorial is outdated. You should refer to the github documentation instead.

@anmolnimbalkar, did your code work after you refracted to CacheFactory ?

It worked for me after I refactored to CacheFactory everywhere the pluralsight tutorial uses DSCacheFactory, and after I changed the injection of “angular-data.DSCacheFactory” for “angular-cache” on app.js file.

1 Like

@CarolinaPowers, you save my ass… thank you so much.
did what you’ve written, and it’s working for me.
Appreciate it.

Same here, CarolinaPowers answer proved practically useful.

One thing that I had a problem with: On following this same Pluralsight tutorial, I added the dependency on $timeout, which I did not remove properly: (I removed from the angular.factory, but not from the eliteApi.js constructor function).
Because of that I was getting a TypeError .get undefined exception on the CacheFactory item.
this was particularly hair-pulling.