tags:

views:

40

answers:

2

OK, so I know you can put $Revision$ in a file, and then set the svn:keywords property on that file so that whenever the file is committed, that variable is replaced with the last committed version number.

I'd like to use this concept to implement a smart caching layer for my template files. I plan on using the svn revision number as part of the key to look up from cache.

Here's some psuedo-code:

function get_from_cache(){
   $key = 'TEMPLATE_CACHE_$Revision$';
   $template = apc_fetch($key);
}

The catch is, I want $Revision$ to be replaced with the current revision number every time a file is committed in the templates/ directory, not every time a file containing the get_from_cache() function is committed. How can I do this?

A: 

It's not directly possible. You could script an update to this file whenever a template is updated, but that's ugly (and will mess up your history).

Easier would be to make the script which does the update on your live server also make a modification to a file (or perform another action, like explicitly clearing the cache) to achieve the same effect.

Andrew Aylett
Then what indirect method is available to me?
Mike Sherov
+1  A: 

You can't do this with keywords. Instead, you can use some scripting to retrieve the last revision of your working copy or the last revision on the svn server and replace it in your script file containing the get_from_cache() function.

You could also set up a post-commit hook that publishes the latest revision of that folder after each commit and retrieve that in some way.

bluebrother
I see, so I can have a post-commit hook that just writes the latest revision number to a file, then read that file in upon execution?
Mike Sherov
Yes, the post commit hook gets the revision number of the commit passed, see http://svnbook.red-bean.com/en/1.4/svn.ref.reposhooks.post-commit.html
bluebrother