1

I'm a web app developer with ASP.NET MVC 5 in server-side and AngularJS in client-side. The navigation, in client-side, is managed with module UI-Router. In server-side I've configured my custom authentication and authorization. When I excecute the app can see a navigation bar with many links. In particular, I have a link named "Overview" that redirects to controller Overview.

Code client (html):

<a ui-sref="Overview">Overview</a>

Code client to redirect (angular):

.config(function ($stateProvider, $urlRouterProvider) {
     $urlRouterProvider.otherwise("Home/Index");
     $stateProvider
        .state("Overview", {
            templateUrl: "Home/Overview",
            url: "/overview"
        })

Controller code:

[OutputCache(Duration=0, NoStore=true)]
[AllowAnonymous]
public ActionResult Overview()
{
    return PartialView();
}

With a breakpoint in line "return PartialView()" to controller code, I can see that controller returns partial view when I click over "overview" in menu app. But when I click second time, the breakpoint does not trigger. I think it's a caching issue.

I have read that caching issue can be generated: * In server-side. * In client-side. * Even IIS.

I have tried many solutions: In server side I use attribute [OutputCache]. When i read in my browser the http headers i can see

enter image description here

In client side i could not find a solution to avoid caching, but i think that UI-Router shouldn't cache anything.

As additional measures I put in my web.config:

<system.webServer>
    <caching enabled="false" enableKernelCache="false" />
</system.webServer>

even, I created my own custom ActionFilterAttribute but did not work.

i don't know what else to do.

PS: sorry for my english

ngLover
  • 4,439
  • 3
  • 20
  • 42
robBerto
  • 196
  • 2
  • 14

2 Answers2

1

If there is any other plugin which does caches its templates, then your solution will clean those templates and make those plugins unusable.. hence your solution is not good.

To solve problem of html caching you should add random query string at the end of html filename... the other solutions you mentioned are for non-caching of api responses and not for static content (html/js/css files)

To add random query string to ur html. either you can use modules like grunt-cache-busting or gulp-rev or use query string as param query-string-cache-busting.

Please note that datetime/file-hash are best cache-busting param

Community
  • 1
  • 1
harishr
  • 17,807
  • 9
  • 78
  • 125
0

Ok, I've found the solution.

Despite avoid caching from server side with attributes like OutputCache, or avoid caching from IIS setting my web.config, the issue persisted.

AngularJS was the guilty. In other post I found the solution.

myApp.run(function($rootScope, $templateCache) {
    $rootScope.$on('$viewContentLoaded', function() {
        $templateCache.removeAll();
    });
});

This solution is provided by Mark Rajcok and Valentyn Shybanov. So thanks to both.

Community
  • 1
  • 1
robBerto
  • 196
  • 2
  • 14
  • @entre I have not checked the question as correct so you can explain. I know that this solution can be inconsistent with UI-bootstrap. [This solution](http://opensourcesoftwareandme.blogspot.com.es/2014/02/safely-prevent-template-caching-in-angularjs.html) seems to solve, but don't work for me. – robBerto Jul 18 '15 at 14:37
  • exactly.. if there is any other plugin which does caches its templates, then this solution will clean those templates and make those plugins unusable.. to solve problem of html caching you should add random query string at its end... the solution you mentioned are for non-caching of api responses and not for static contents – harishr Jul 19 '15 at 05:56
  • so I can put a random query string to avoid cache, and does not query string make plugin unusable? – robBerto Jul 19 '15 at 11:24
  • 1
    no just add random query string to only ur html. to do that either you can use modules like [grunt-cache-busting](https://www.npmjs.com/package/grunt-cache-busting) or use query string as param [query-string-cache-busting](http://stackoverflow.com/questions/9692665/cache-busting-via-params) or datetime as params which is best cache-busting param – harishr Jul 21 '15 at 04:13
  • if you are using gulp look at [this](https://github.com/bustardcelly/gulp-rev-append) – harishr Jul 21 '15 at 04:18
  • You've given me guidance very well!. Thanks for your help. – robBerto Jul 22 '15 at 06:56
  • putting my comments as an answer – harishr Jul 22 '15 at 08:01