CodeIgniter Forums
[Q] can I cache JSON response - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: [Q] can I cache JSON response (/showthread.php?tid=11323)



[Q] can I cache JSON response - El Forum - 09-04-2008

[eluser]vlad_ci[/eluser]
most of the stuff I send to my client is JSON data,
so wanted to ask if I could use CI's caching somehow
to cache JSON responses (because some of them are not user
specific)

thank you


[Q] can I cache JSON response - El Forum - 09-04-2008

[eluser]mglinski[/eluser]
Sure, make each JSON call a seperate function in your controllers.
Then at the beginning of the function, call the caching method.
-Matt


[Q] can I cache JSON response - El Forum - 09-04-2008

[eluser]vlad_ci[/eluser]
[quote author="XtraFile" date="1220561308"]Sure, make each JSON call a seperate function in your controllers.
Then at the beginning of the function, call the caching method.
-Matt[/quote]

Thank you, what about
Quote:Warning: Because of the way CodeIgniter stores content for output, caching will only work if you are generating display for your controller with a view.

from the CI documentation. Since my JSON's are not 'viewes'
will
Code:
output->cache(n);
work?


[Q] can I cache JSON response - El Forum - 09-04-2008

[eluser]mglinski[/eluser]
Then no it will not work the current CI way. The easiest way to enable it is to make a json.php file in the views folder with only one variable in it( <?=$json?> for example).
Then have all your json calls send the json data to that view. As long as the URL is different a different cache file will be generated even if you are using thh same view file for all json calls.
-Matt


[Q] can I cache JSON response - El Forum - 09-04-2008

[eluser]vlad_ci[/eluser]
ok,
I understand now.
Having different URLs allows to use the same view
for different 'data' and still cache them uniquely

thank you