Matthew Shafer .net
I program stuff.


In my post yesterday I mentioned that I was managing what data I had written to xcache in my xcacheDynamic class because if a post is added while there are cached values we need to clear those values so users can see the new post right away.

In the xcacheStatic class I tried to use xcache_unset_by_prefix() but I assume that is a xcache 1.3 feature as in 1.2.2, which I currently run, it caused a function not defined error. This definitely makes things harder as I attach a prefix to every entry in xcache so deleting using this function makes things trivial.

This is what I did in the xcacheStatic and xcacheDynamic classes, I used an associative array. So essentially what that means is if the prefix is test_ then in the cache there is a test_array entry that stores an associative array containing all the items I have added to the cache. Why an associative array? I can set the key to the hash of the query and the value to the hash of the query. Then it is stored inside the var cache. This makes it easy to see if the value already exists in the array using isset(), thus if it exists I don't need to push something else onto the array. It's also nice because when we purge the cache I am able to iterate through the array and each value is the hash i need to delete. The nice thing in PHP is you can iterate through associative arrays.

The only reason I need this is if an update/insert/delete happens to something in the database and the cache hasn't been garbage collected yet. This way theres no waiting for the cache to expire in order to show new data, it is shown after the data is inserted in the database. Now I wouldn't need to use the array method if I were able to delete by prefix, but thats okay as this method works fine.

Oh and I only need to update the array when something is being written to the var cache.

the pseudocode is something like

if(don't have the array in xcache)
{
create an array containing the hash as the key and as the value.
write that as something like prefix_somethingweknow into xcache
}
else
{
grab the array from xcache
check if it contains this value
if it doesn't then add it and write the entire thing to xcache
}
Categories: projects
Date: 04/29/10

A few days ago I was reading about caching SQL queries using things like memcached. So I decided to test out the possibility of adding it to the database queries. I wrote an xcacheDynamic class that handles keeping track of the cached var's. More on why I have to manually keep track of the var's cached by xcache in another post. I was seeing pretty decent performance increases on my local build but one thing to note is that when I run MySQL queries the mds program on my mac decides it needs to index stuff so that uses a ton of processor. Anyway even doubling the requests a second from no caching was still less than with caching. The thing is that I have Indexes set up in MySQL which should make the SELECT's have pretty good performance. I do think that on large datasets the caching will probably show a bigger advantage when it comes to performance. There are probably some places where I could cut corners with caching make things quick but cutting corners can lead to issues. But I did notice some places where I could improve the code which might lead to slightly higher performance.

I still need to run more performance tests, possibly I will run some tests in a VM once I get the code cleaned up. The nice thing with this way of caching is that themes can still be dynamic, so themes can kill performance but at least the "core" of Feedstock is quick.
Categories: projects
Date: 04/28/10

So I know the blog link used to say I was working on a blogging program. Well here it is. I got it to the point where I felt as though I should be using it on here. I'll be releasing the code pretty soon as I feel it might be useful to other people.
Tags: site
Categories: projects
Date: 04/25/10

<- Previous Page