Hari
Hari

Reputation: 301

How to clear smarty templates_c folder using php code

I have an issue in smarty cache. When an update content from admin website I am able to view the new content immediately but when i check the same page in main site i see the old content instead of new content.When i clear the templates_c dir in server and refresh the main site,I see the new content at the first attempt.I believe somewhere it has the problem with caching.Please give me a solution for this asap.Thank you.

Upvotes: 1

Views: 1916

Answers (1)

periklis
periklis

Reputation: 10188

Something like this should do (I haven't tested it myself):

<?php
$path = 'path/to/templates_c';
$dir = new DirectoryIterator($path);
foreach ($dir as $fileinfo) {
    if ($fileinfo->isFile()) {
        unlink($fileinfo->getPath());
    }
}
?>

By the way, be very cautious when dealing with unlink(), you may accidentally delete files you didn't mean to

Upvotes: 1

Related Questions