when i opened that view for the second dont rerun the ajax i use this code but is not correct
Unclear. What does "not correct" mean? You have a "username" input but are not using vary by parameter. As written you are leaking user information which is a very poor design. Is this what's not working as expected? You keep getting the same user information
when the username changes?
caching does not stop the ajax call, it just caches the result. but in your case, as the response varies by user, the server can not cache, and by default the browser does not cache ajax calls.
the correct solution is for the client code to cache the result in a cookie or local storage and only make the ajax call when necessary.
To reiterate, you need to vary by the username parameter otherwise every application user your will see the same cached result set by the first user. Then by the first user to hit the action every 1000 seconds.
There can be other issues with the design. Every time the autocomplete is invoked, it appends the same cached data to the HTML table. The design seems a little off but perhaps we do not have the entire design picture.
Anyway, the official Output Cache documentation is quite good. The docs explain the definitions with sample code.
Please stop asking the same question over and over. If the solutions in your previuos threads are not working as expected then explain what's not working. Asking he same question wastes the community's time. Please stop!
i will not stop asking until i get the answer if you know the answer post it if not let me answer
The SO thread you shared explains why layout.cshtml cannot be cached. This fact is mirrored in the links I've provided in you previous threads. Why do you NOT believe the reference documentation? Also, in your previous threads, you are not returning
JSON not a View yet you keep asking about Views.
At this point it seems you need to take a step back and learn the fundamentals. Asking the same question over and over is not going to change the results. Lastly, share your code so we can review your code.
var row;
$.ajax({
type: 'get',
url: '/AutoComplete/check_user_permission_Module',
cache: true,
data: { username: $("#username").val() },
success: function (response) {
data = $.map(response, function (v, a) {
row += '<tr><td><input type="text" value="' + v.module + '"></td><td><input type="text" value="' + v.Username + '"></td><td><input type="text" value="' + v.read1 + '"></td><td><input type="text" value="' + v.write + '"></td><td><input type="text" value="' + v.create1 + '"></td><td><input type="text" value="' + v.delete1 + '"></td><td><input type="text" value="' + v.submit + '"></td><td><input type="text" value="' + v.cancel + '"></td><td><input type="text" value="' + v.amend + '"></td><td><input type="text" value="' + v.report + '"></td><td><input type="text" value="' + v.import + '"></td><td><input type="text" value="' + v.export + '"></td></tr>';
})
$('#tb_module').append(row);
}
}).done(function () {
for (var i = 1; i < $("#tb_module tr").length; i++) {
//Modules
if ($("#tb_module").find("tr:eq(" + i + ")").find("td:eq(0)").find("input").val() == "Account") {
$(".tr_account").addClass("show")
}
if ($("#tb_module").find("tr:eq(" + i + ")").find("td:eq(0)").find("input").val() == "Buying") {
$(".tr_buying").addClass("show")
}
if ($("#tb_module").find("tr:eq(" + i + ")").find("td:eq(0)").find("input").val() == "Stock") {
$(".tr_stock").addClass("show")
}
if ($("#tb_module").find("tr:eq(" + i + ")").find("td:eq(0)").find("input").val() == "Selling") {
$(".tr_selling").addClass("show")
}
if ($("#tb_module").find("tr:eq(" + i + ")").find("td:eq(0)").find("input").val() == "Manufacturing") {
$(".tr_manufacture").addClass("show")
}
if ($("#tb_module").find("tr:eq(" + i + ")").find("td:eq(0)").find("input").val() == "Healthcare") {
$(".tr_healthcare").addClass("show")
}
if ($("#tb_module").find("tr:eq(" + i + ")").find("td:eq(0)").find("input").val() == "Setup") {
$(".tr_setup").addClass("show")
}
if ($("#tb_module").find("tr:eq(" + i + ")").find("td:eq(0)").find("input").val() == "Human Resources") {
$(".tr_human_resources").addClass("show")
}
}
})
i want when i open that view for the first time ajax will execute then by if condition the design will display i want for the first time when i open the view that ajax and if condition
will run but for the second time and so on when i open that view imediatly design will display without execute ajax and check if condition how can i do it?
Your requirement is not clear. I think you expect the done() promise should not fire if the Output Cache is enabled. That's not how AJAX works.
What's a little confusing is you're executing an AJAX request when the page loads. Why? Simply populate the page from the server rather than making two HTTP requests.
var row;
$.ajax({
type:'get',
url:'/AutoComplete/check_user_permission_Module',
cache:true,
data:{ username: $("#username").val()},
success:function(response){
data = $.map(response,function(v, a){
row +='<tr><td><input type="text" value="'+ v.module+'"></td><td><input type="text" value="'+ v.Username+'"></td><td><input type="text" value="'+ v.read1 +'"></td><td><input type="text" value="'+ v.write +'"></td><td><input type="text" value="'+ v.create1 +'"></td><td><input type="text" value="'+ v.delete1 +'"></td><td><input type="text" value="'+ v.submit +'"></td><td><input type="text" value="'+ v.cancel +'"></td><td><input type="text" value="'+ v.amend +'"></td><td><input type="text" value="'+ v.report +'"></td><td><input type="text" value="'+ v.import+'"></td><td><input type="text" value="'+ v.export+'"></td></tr>';})
$('#tb_module').append(row);}}).done(function(){for(var i =1; i < $("#tb_module tr").length; i++){//Modulesif($("#tb_module").find("tr:eq("+ i +")").find("td:eq(0)").find("input").val()=="Account"){
$(".tr_account").addClass("show")}if($("#tb_module").find("tr:eq("+ i +")").find("td:eq(0)").find("input").val()=="Buying"){
$(".tr_buying").addClass("show")}if($("#tb_module").find("tr:eq("+ i +")").find("td:eq(0)").find("input").val()=="Stock"){
$(".tr_stock").addClass("show")}if($("#tb_module").find("tr:eq("+ i +")").find("td:eq(0)").find("input").val()=="Selling"){
$(".tr_selling").addClass("show")}if($("#tb_module").find("tr:eq("+ i +")").find("td:eq(0)").find("input").val()=="Manufacturing"){
$(".tr_manufacture").addClass("show")}if($("#tb_module").find("tr:eq("+ i +")").find("td:eq(0)").find("input").val()=="Healthcare"){
$(".tr_healthcare").addClass("show")}if($("#tb_module").find("tr:eq("+ i +")").find("td:eq(0)").find("input").val()=="Setup"){
$(".tr_setup").addClass("show")}if($("#tb_module").find("tr:eq("+ i +")").find("td:eq(0)").find("input").val()=="Human Resources"){
$(".tr_human_resources").addClass("show")}}})
i want when i open that view for the first time ajax will execute then by if condition the design will display i want for the first time when i open the view that ajax and if condition
will run but for the second time and so on when i open that view imediatly design will display without execute ajax and check if condition how can i do it?
that is not how caching works. The Ajax call be be made every time the page loads (navigated to) whether it comes from cache or not.
Member
75 Points
513 Posts
how to cash view
Feb 29, 2020 02:53 PM|zhyanadil.it@gmail.com|LINK
i have a view which return data from sql by ajax i want to cash that view when i opened it for the first time cash that view result query
when i opened that view for the second dont rerun the ajax i use this code but is not correct
web.config
i want to cache this ajax don't rerun by every rerefesh untill cache is cleared then rerun ajax
All-Star
53011 Points
23596 Posts
Re: how to cash view
Feb 29, 2020 03:46 PM|mgebhard|LINK
Your code does NOT return a View! It returns JSON.
Anyway, I built a basic text using the official and openly published OutPutCache documentation and caching simply just works as written in the docs.
https://forums.asp.net/t/2164595.aspx?how+to+cash+view+
Unclear. What does "not correct" mean? You have a "username" input but are not using vary by parameter. As written you are leaking user information which is a very poor design. Is this what's not working as expected? You keep getting the same user information when the username changes?
Member
75 Points
513 Posts
Re: how to cash view
Feb 29, 2020 06:10 PM|zhyanadil.it@gmail.com|LINK
i have this ajax i want to cache it for one day run just one time
i wrote that but when i refresh the page every time that ajax will execute i want execute just one time it mean cache it
All-Star
58174 Points
15647 Posts
Re: how to cash view
Feb 29, 2020 07:57 PM|bruce (sqlwork.com)|LINK
caching does not stop the ajax call, it just caches the result. but in your case, as the response varies by user, the server can not cache, and by default the browser does not cache ajax calls.
the correct solution is for the client code to cache the result in a cookie or local storage and only make the ajax call when necessary.
Member
75 Points
513 Posts
Re: how to cash view
Feb 29, 2020 08:19 PM|zhyanadil.it@gmail.com|LINK
can you explain it by example?
All-Star
53011 Points
23596 Posts
Re: how to cash view
Feb 29, 2020 08:38 PM|mgebhard|LINK
There's example code and an explanation in your duplicate post.
https://forums.asp.net/p/2164595/6295964.aspx?how+to+cash+view+
To reiterate, you need to vary by the username parameter otherwise every application user your will see the same cached result set by the first user. Then by the first user to hit the action every 1000 seconds.
There can be other issues with the design. Every time the autocomplete is invoked, it appends the same cached data to the HTML table. The design seems a little off but perhaps we do not have the entire design picture.
Anyway, the official Output Cache documentation is quite good. The docs explain the definitions with sample code.
https://forums.asp.net/t/2164595.aspx?how+to+cash+view+
Member
75 Points
513 Posts
Re: how to cash view
Mar 01, 2020 07:17 AM|zhyanadil.it@gmail.com|LINK
How to cache .cshtml layout in MVC? it mean when i opened it at first time the page will designed if i opened it for second time don't redesign it
All-Star
53011 Points
23596 Posts
Re: how to cash view
Mar 01, 2020 01:44 PM|mgebhard|LINK
You asked this question two times, This is the third.
https://forums.asp.net/p/2164599/6295984.aspx?Re+how+to+cache+ajax+result
https://forums.asp.net/p/2164595/6295964.aspx?how+to+cash+view+
Please stop asking the same question over and over. If the solutions in your previuos threads are not working as expected then explain what's not working. Asking he same question wastes the community's time. Please stop!
Member
75 Points
513 Posts
Re: how to cash view
Mar 01, 2020 03:31 PM|zhyanadil.it@gmail.com|LINK
i will not stop asking until i get the answer if you know the answer post it if not let me answer
All-Star
53011 Points
23596 Posts
Re: how to cash view
Mar 01, 2020 03:46 PM|mgebhard|LINK
The SO thread you shared explains why layout.cshtml cannot be cached. This fact is mirrored in the links I've provided in you previous threads. Why do you NOT believe the reference documentation? Also, in your previous threads, you are not returning JSON not a View yet you keep asking about Views.
At this point it seems you need to take a step back and learn the fundamentals. Asking the same question over and over is not going to change the results. Lastly, share your code so we can review your code.
Member
75 Points
513 Posts
Re: how to cash view
Mar 02, 2020 05:40 AM|zhyanadil.it@gmail.com|LINK
i have this view
i want when i open that view for the first time ajax will execute then by if condition the design will display i want for the first time when i open the view that ajax and if condition
will run but for the second time and so on when i open that view imediatly design will display without execute ajax and check if condition how can i do it?
None
0 Points
14 Posts
Re: how to cash view
Mar 02, 2020 02:18 PM|vikas_jk|LINK
Use output cache in MVC
https://docs.microsoft.com/en-us/aspnet/mvc/overview/older-versions-1/controllers-and-routing/improving-performance-with-output-caching-cs
https://qawithexperts.com/article/asp.net/outputcache-in-aspnet-mvc-caching-in-mvc/95
All-Star
53011 Points
23596 Posts
Re: how to cash view
Mar 02, 2020 03:11 PM|mgebhard|LINK
Your requirement is not clear. I think you expect the done() promise should not fire if the Output Cache is enabled. That's not how AJAX works.
What's a little confusing is you're executing an AJAX request when the page loads. Why? Simply populate the page from the server rather than making two HTTP requests.
All-Star
58174 Points
15647 Posts
Re: how to cash view
Mar 02, 2020 03:20 PM|bruce (sqlwork.com)|LINK
that is not how caching works. The Ajax call be be made every time the page loads (navigated to) whether it comes from cache or not.