Prevent partials from caching...

6,392 views
Skip to first unread message

vs

unread,
Aug 16, 2012, 5:13:20 PM8/16/12
to ang...@googlegroups.com

Our templates are valid for onetime use. Basically, they'll need to be
reloaded on every use. 

An obvious solution is to use unique urls. But how can the router urls be changed post initialization?

Disabling browser caches is not an option, since we need this for normal operations.

thanks,
-vs

Pawel Kozlowski

unread,
Aug 16, 2012, 5:32:59 PM8/16/12
to ang...@googlegroups.com
hi!

You could remove templates from the $templateCache
(http://docs.angularjs.org/api/ng.$templateCache) when those are no
longer needed.

Cheers,
Pawel
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To post to this group, send email to ang...@googlegroups.com.
> To unsubscribe from this group, send email to
> angular+u...@googlegroups.com.
> Visit this group at http://groups.google.com/group/angular?hl=en.
>
>

vs

unread,
Aug 16, 2012, 5:51:22 PM8/16/12
to ang...@googlegroups.com
perfect. thanks much.
Message has been deleted

leeh...@gmail.com

unread,
Nov 12, 2012, 2:32:44 PM11/12/12
to ang...@googlegroups.com, vivek.s...@gmail.com
when partial templates are rendered, are they automatically cached in templateCache? is there an example of how to explicitly remove a partial template from the template cache? how do i know what key to specify? thanks!

Pawel Kozlowski

unread,
Nov 12, 2012, 2:37:35 PM11/12/12
to ang...@googlegroups.com
Hi!

On Mon, Nov 12, 2012 at 8:32 PM, <leeh...@gmail.com> wrote:
> when partial templates are rendered, are they automatically cached in
> templateCache?

Technically speaking those are added to the cache as soon as
downloading completes.

> is there an example of how to explicitly remove a partial
> template from the template cache?

This SO thread has more info and an example of adding things to the
$templateCache:
http://stackoverflow.com/a/12346901/1418796

Removing would be similar, that is, you need to grab a reference to
the $templateCache and call remove or removeAll on it.
More info here: http://docs.angularjs.org/api/ng.$cacheFactory

> how do i know what key to specify?
The key is simply a URL of your template.

Hope this helps,
Pawel

leeh...@gmail.com

unread,
Nov 12, 2012, 5:34:33 PM11/12/12
to ang...@googlegroups.com
Thanks for the quick reply! I'll try it out and update.

leeh...@gmail.com

unread,
Nov 15, 2012, 12:15:11 AM11/15/12
to ang...@googlegroups.com, leeh...@gmail.com
I don't think removing from $templateCache solves the problem. I did a removeAll() and verified that the cache size was 0, but it seems like the browser is caching the static html template. Is there a way to control this caching behavior within the app?

Johan

unread,
Nov 15, 2012, 3:23:47 AM11/15/12
to ang...@googlegroups.com, leeh...@gmail.com
I had this problem in early version (pre 1.0 release) - you can use the old trick of appending a random string to the template url. In you app you can define this random value as a variable and simply change it when you need to flush old templates.

Anila Jacob

unread,
May 13, 2015, 7:39:58 AM5/13/15
to ang...@googlegroups.com, vivek.s...@gmail.com

Hi All,

I want to prevent caching in angular.for that i set the cache property to false.After doing this i request the same url .But didn't send that requst to my server.
The code is ,

 $http({
                       
                        cache : false,
                       
                        method: "GET",
                       
                        url:"http://192.168.10.118:8087/cisms/manageit/ciAvailableWidget/ciAvailableSetting"
                       
                    }).success(function(data) {
                             
                     
                   
                    }).error(function(data) {
               
                    
                         
                    });   


can u help me?
Reply all
Reply to author
Forward
0 new messages