Controlling cache |
[eluser]Iconfinder[/eluser]
Hi I have been working with the CI cache and want to build a search function that uses the parameter 'q' so the URI ends up with /search?q=[searchterm] When I activate caching it caches every search without looking at q parameter. So /search?q=cat and /search?q=dog will end up in the same cached file. Is it possible to add some kind of ID when using the output->cache ? This is my snippet for activating the cache. The expire time is added to the config file. Code: $this->output->cache($this->config->item('cache_expire'));
[eluser]ChrisMiller[/eluser]
Hmm although its not possible to add that function without modifying the source code of the Output.php file its odd why that wont cache correctly. Im not sure entirely about the cache system however this is what generates the unique id... Code: $uri = $CI->config->item('base_url'). Try changing your config item uri_protocoll to PATH_INFO and see what happens. Like I said im not sure about this entirely but I will look into it and do some experiments in the morning for ya...
[eluser]Iconfinder[/eluser]
Thank you for your reply. There were no settings in the config file that made it include parameters in the $uri variable. I looked in URI.php but since this is used to locate the right controller it really messes up things if $uri is changed. I ended up adding two lines to Output.php so I can add my own $key before the URI is run through MD5. A similar change is made in _write_cache(). Code: function _display_cache(&$CFG, &$URI) I wonder how other sites have implemented search with GET parameters.
[eluser]InsiteFX[/eluser]
This must have something todo with CodeIgniter because a url should except that Code: /search?q=cat InsiteFX
[eluser]John_Betong_002[/eluser]
[quote author="Iconfinder" date="1301947043"]Hi I have been working with the CI cache and want to build a search function that uses the parameter 'q' so the URI ends up with /search?q=[searchterm] When I activate caching it caches every search without looking at q parameter. So /search?q=cat and /search?q=dog will end up in the same cached file. Is it possible to add some kind of ID when using the output->cache ? This is my snippet for activating the cache. The expire time is added to the config file. Code: $this->output->cache($this->config->item('cache_expire')); Looks like you are using Page Caching and have opened up a "can of worms". It is so easy to implement but unfortunately not easy to temporarily prevent the old cache from raising your old search From the User Guide: Quote:Deleting Caches This topic has been covered and a forum search for "clearPageCache" should be helpful.
[eluser]ChrisMiller[/eluser]
Thats not the problem he is having. He WANTS to cache things however because of his url structure and added options it is not functioning correctly. Example being Code: somesite.com/controller/search_function?q=my_term is being cached and when the next user is requesting Code: somesite.com/controller/search_function?q=a_new_term which is showing the cached version of the first request.
[eluser]John_Betong_002[/eluser]
@ChrisMiller Did you search for “clearPageCache". There is only one other result apart from this thread: http://ellislab.com/forums/viewthread/62951/ The problem posed was deleting a particular existing search cached string. The site had dynamic data and a new search should not retrieve the static, historical result from the cache. The solution was to use the function supplied to delete the previous cache searched string and to initiate a new search on the latest revised string. The latest search was then cached. Coincidentally I am in the process of trying to integrate Caching on one of my dynamic sites and it is not as simple as I was led to believe
[eluser]ChrisMiller[/eluser]
I did not search for it but the problem is suppose you want to store the results for all the search strings, as nobody ever searches for the exact same thing back to back so a cache would not help in that aspect. From the sounds of it he is looking for a unique file for each unique search term. Hence why he is assigning his own ID's now as that would enable him to generate them on his own. Honestly he is probally going about it the best way shy of writing your own cache class which is an entire new aspect. Only problem is every update to CodeIgniter he has to go an remodify the output class.
[eluser]ChrisMiller[/eluser]
I cache them for 15minutes as to help keep the load down on the website as I do not have big money pockets like the bigger companies do have. |
Welcome Guest, Not a member yet? Register Sign In |