So I guess you want to replace 'cache' with the content of said variable, not with its name:
sed 's#^$cache_directory = ../cache.;#$cache_directory = '$new_cache_directory'#' script.php
So you have different problems to solve: Normally a sed command uses slashes to separate the parts: 's/foo/bar/'. When dealing with paths, this is disturbing, but we can use many delimiters - they are just implicitly declared in following the 's'.
Problem 2 is similar. We often specify the command in single quotes:
sed 'command' file
But here we have apostrophes around ./cache - what to do? One idea would be, to use
sed "command" file
instead, which often works, but not here. The apostrophes prevent the Dollar-sign from being interpreted, but quotes wouldn't prevent that. Often, you don't even need apostrophes, and can write:
sed s/standart/standard/g sample.txt
but again, you have $cache_directory as a variable in the command, which would be interpreted. So I just replace the apostrophes with the joker sign, dot, and would be really surprised, if some other expression would match that part:
xy/cachei - not very probable, is it?
But you like $new_cache_directory to be replaced with the content of the variable, so I switch masking off with
= ', insert the variable, and switch masking on again to finish the command with '#'.