“cacher layer” for google-generated images

可紊 提交于 2019-12-25 06:32:15

问题


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!


回答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



来源:https://stackoverflow.com/questions/6204569/cacher-layer-for-google-generated-images

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!