Welcome Guest, Not a member yet? Register   Sign In
Controlling cache
#1

[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'));
#2

[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').
       $CI->config->item('index_page').
       $CI->uri->uri_string();

$cache_path .= md5($uri);

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

[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)
{
        $cache_path = ($CFG->item('cache_path') == '') ? APPPATH.'cache/' : $CFG->item('cache_path');

        // Build the file path.  The file name is an MD5 hash of the full URI
        $uri = $CFG->item('base_url').
                $CFG->item('index_page').
                $URI->uri_string.
                $key;

I wonder how other sites have implemented search with GET parameters.
#4

[eluser]InsiteFX[/eluser]
This must have something todo with CodeIgniter because a url should except that
Code:
/search?q=cat

// PHP.net
/search?arg=value

InsiteFX
#5

[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'));
[/quote]

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 Smile

From the User Guide:
Quote:Deleting Caches

If you no longer wish to cache a file you can remove the caching tag and it will no longer be refreshed when it expires. Note: Removing the tag will not delete the cache immediately. It will have to expire normally. If you need to remove it earlier you will need to manually delete it from your cache folder.

This topic has been covered and a forum search for "clearPageCache" should be helpful.
 
 
 
#6

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

[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 Sad
 
 
 
#8

[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.
#9

[eluser]wh1tel1te[/eluser]
Search result pages shouldn't be cached.
#10

[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.




Theme © iAndrew 2016 - Forum software by © MyBB