Php Flow » Php

PHP Cache : Create Cache File Depend On File

In previous Tutorial I was described use of cache terminology in terms of website performance as well cache file with fixed expiry date. Now In this Tutorial We will create cache file based on original file dependencies, In Other word cache file dependent on other file.this method prevents unecessary call webservices, such as those required to retrieve data for inclusion in a page, and prevents regenerating pages regularly even when nothing responce has changed. This is the approach used on the below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function checkDependenciesCache()
  {
      $path = 'cache/facebook.xml';
	  $oriFile = 'facebook.xml';
	  echo 'ddddddddd' . filemtime($oriFile);
	  echo 'path='. @filemtime($path);
      if ((file_exists($path)) && (filemtime($oriFile) > filemtime($path)) )
      {
	    $cache = fopen($path, 'w+');
        fwrite($cache, file_get_contents($oriFile));
        fclose($cache);
      }
      else
      {
        $cache = fopen($path, 'r');
        return file_get_contents($path);
        fclose($cache);
      }
  }

How to call

1
checkDependenciesCache();
Did you enjoy this article? Share it!

About the Author:

Hi, This is Parvez Alam from India. I am software developer with 4 years’ experience in web development. I have submitted articles on PHP, Mysql, Magento,CSS, HTML, jQuery, web designing and social API. You can subscribe to my blog via RSS/Twitter/Google plus and Facebook.

Random Posts

One thought on “PHP Cache : Create Cache File Depend On File

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>