Welcome Guest, Not a member yet? Register   Sign In
Caching and headers
#61

[eluser]Aquillyne[/eluser]
[quote author="Randy Casburn" date="1216794634"]I'm glad you edited your post. My attempts at helping you recognize inconsistencies in what you've presented along the way have failed and I accept responsibility for that.


Earlier you said...
Quote:I don’t like this shift back to focus on MIME-types.

Now you say...

Quote:You can’t always specify headers in the view. CSS, images, etc., which need mime-type headers...
[/quote]

There are no inconsistencies in my posts. If you half-quote anything it can become something else.

Yes, CSS, images, etc., need mime-types. But 404's need 404's. And so on. Mime-types are only half of it. Headers is the issue, as the rest of the quote went on to say. I said I don't want to focus on mime-types, because mime-types are only a subset of headers.
#62

[eluser]Randy Casburn[/eluser]
OK -- Fair enough.
#63

[eluser]Aquillyne[/eluser]
[quote author="Randy Casburn" date="1216799901"]OK -- Fair enough.[/quote]

Yay Smile
#64

[eluser]dcunited08[/eluser]
Any update on this issue? I have a similar problem where I am reading all my css files into one file to be cached.
#65

[eluser]beemr[/eluser]
You should still be able to use either Suffix cache or Aquillyne's cache header approach.

I've been working with 1.7svn, and I haven't had to make any changes to suffix cache that come to mind. I load a base php file for css and that file calls the load on a series of preliminary php files such as a css reset and a grid setup. I'd recommend suffix cache, just because you'd want to avoid the potential for uri clashes between your css/js and your controllers

EDIT: Forgot that I actually did make changes for it to work with 1.7
#66

[eluser]Aquillyne[/eluser]
My cache headers hack (on the wiki) works perfectly. People still don't get it - it has nothing, nothing, NOTHING to do with suffixes or uri conflicts. It is a simple extension to the caching mechanism that makes the cache return any headers that were sent with $this->output when the cache was written. This has nothing to do with the way the cache filename is generated. If you want to cache and return your CSS, use my hack and keep shouting here until it's included in the CI core code! The current code even contains a comment from the programmer saying it needs my hack, for gods sake! Tongue
#67

[eluser]Arjen van Bochoven[/eluser]
Ok, with CI 1.7.0 the above fix is broken. The format of $this->header array has changed.

I also need header caching, so I used serialize() to store the header data. This will make you less dependent on the internal storage mechanism of the headers. I also separated the expiration string. In practice it looks like this:

in _write_cache() I replaced

Code:
fwrite($fp, $expire.'TS--->'.$output);

with

Code:
fwrite($fp, serialize( array( 'exp' => $expire, 'headers' => $this->headers, 'output' => $output)));

and in _display_cache(), I replaced

Code:
// Strip out the embedded timestamp        
if ( ! preg_match("/(\d+TS--->)/", $cache, $match))
{
    return FALSE;
}

// Has the file expired? If so we'll delete it.
if (time() >= trim(str_replace('TS--->', '', $match['1'])))
{        
    @unlink($filepath);
    log_message('debug', "Cache file has expired. File deleted");
    return FALSE;
}

// Display the cache
$this->_display(str_replace($match['0'], '', $cache));

with

Code:
// Restore the cache array
$cache = unserialize($cache);

// Validate cache file
if ( ! isset($cache['exp'] ) OR ! isset($cache['headers']) OR ! isset($cache['output']))
{
    return FALSE;
}

// Has the file expired? If so we'll delete it.
if (time() >= trim($cache['exp']))
{        
    @unlink($filepath);
    log_message('debug', "Cache file has expired. File deleted");
    return FALSE;
}

// Restore headers
$this->headers = $cache['headers'];
        
// Display the cache
$this->_display($cache['output']);
#68

[eluser]Aquillyne[/eluser]
Arjen, your solution is actually even neater than mine. But it's exactly the same concept, which CI is direly lacking.

I continue to advocate header caching, it's so sorely missing - I now advocate it with Arjen's code rather than mine.
#69

[eluser]Arjen van Bochoven[/eluser]
Hey Aquillyne,

Glad you like it, do you want me to update the page in the wiki? I suggest to put it there as an extension for Output.php (MY_Output.php)

grz

Arjen
#70

[eluser]Aquillyne[/eluser]
Do test the code first (mine is tested). To make sure it works, use it to output a cached image or linked stylesheet. Then yes, update the wiki.




Theme © iAndrew 2016 - Forum software by © MyBB