Welcome Guest, Not a member yet? Register   Sign In
[Q] can I cache JSON response
#1

[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
#2

[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
#3

[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?
#4

[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
#5

[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




Theme © iAndrew 2016 - Forum software by © MyBB