0

The question is prompted by comment to an earlier question of mine. I've never heard of a cacher layer.

The suggestion was to cache google-generated images in this cacher-layer thingie. Can someone give the a pointer to the details of such a layer? "Details" = where does it live? how do I access it? and more.

Thanks so much!

Community
  • 1
  • 1
Pete Wilson
  • 8,610
  • 6
  • 39
  • 51

1 Answers1

1

I will explain what I meant.

First of all I needed this system because Google Chart API has some requests-daily CAP so I needed something to bypass it.

The engine was pretty simple.
Consider the vanilla solution: in your HTML you have your img' src directly poiniting to google.

<img src="//google.chart.api?params123">

With a cacher you will not point directly to Google but to your cacher engine:

<img src="//yourwebsite/googleImageCacher.php?id=123">

Now your googleImageCacher.php is dead simple:

It checks if the image requested is found in a cache (it could be a file or whatever) if it's not present then it will request it to google save it and echo.

Something like: (pseudocode)

     $imageAssociation = array( '123' => '//google.chart.api?params123'
                                'image2' => '//google.chart.api?otherparma'  );

     if ( file_exists( 'imageCacheDir/' . $_GET['id'] ) ) {

            echo file_get_contents('imageCacheDir/' . $_GET['id']);

     } else {

            //> Request the image to google
            //> Save it in the imageCacheDir
            //> Print it.

     }

Of course you can simplement some expiration time in your googleImageCacher.php

dynamic
  • 46,985
  • 55
  • 154
  • 231