views:

405

answers:

3

I recently implemented gzipping of my content with php's ob_gzhandler function which keeps things really simple.

I'm now trying to add this content to my memcache, and was hoping there was a simple way to do that as well, but I haven't been able to find anything online about accomplishing this.

I've only used memcache in the past to store data which was held in a variable,but with the ob_gzhandler, I don't have a variable with the data in it. So I unfortunately don't even know where to start with this.

Thanks Pete

-----Edit for more information------------------------- As Cody commented below, apparently my question was/is vague. Sorry about that, I'm trying to give as much info as possible, but am really a bit lost in this process.

When I've used memcache before, I have checked if the data exists in memcache based on a hash of the url request. If there was a match, i grabbed the cached data. If not, then I'd make the page and store it in the cache.

Now I'm trying to do the same thing, but with gzipped data using the php ob_gzhandler.

But as Ciaran has stated, it might make more sense to just take the hit of storing the non-gzipped data.

At the same time, it would be nicer to store the gzipped version, as it is both smaller so I could store more in the cache, and aren't almost all browsers gzip compatible?

+1  A: 

It sounds like you are asking about a passive cache, where you have some code that queries a cache, and upon a cache miss, it generates the data, inserts it into your cache and then returns it. The short of the story is that your code will always return a chunk of data, but whether it returns it by calculating or by hitting the cache, well, the callee code doesnt care.

Is this correct?

Ultimately, your question is vague and doesnt contain enough information.

Cody Caughlan
Sorry about that Cody, i've tried to add a bit more, but, you are correct in the process I am using to create the cached data
pedalpete
+1  A: 

ob_gzhandler() will return either a string or false, depending on whether the client browzer supports gzip, deflate or no encoding. You're probably using this function via ob_start() or similar.

Because the result is different per-client, it's not a great idea to try and cache the result (i.e. in some cases it'll be FALSE, in some cases it'll be a 'deflate'-encoded response and in others it'll be a 'gzip'-encoded response).

It would seem to make more sense to cache the content that's being gzipped, and take the 'hit' of it being re-compressed each requests - in practice this shouldn't be a huge overhead.

Ciaran McNulty
A: 

If it's just about reducing the number of bytes transferred into storage, there are a number of clients that can compress the data before it's sent to memcache - depending on the size (compressing 50K is useful, 5 bytes, not so much). As @Ciaran says, the overhead to then re-compress for the final delivery - if required - isn't so much.

Alister Bulman