本文介绍了“cacher layer”用于谷歌生成的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过对。我从来没有听说过cacher层。

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

建议是在这个cacher-layer thingie中缓存谷歌生成的图像。有人可以给出指向这样一层的细节的指针吗? 细节=它住在哪里?我该如何访问它?还有更多。

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.

非常感谢!

推荐答案

我会解释我的意思。

首先我需要这个系统因为Google Chart API有一些请求 - 每日CAP所以我需要一些东西来绕过它。

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

引擎很简单。

考虑一下vanilla解决方案:在你的HTML中,你的img'src直接指向google。

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">

使用cacher,您不会直接指向Google,而是指向您的cacher引擎:

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

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

现在你的 googleImageCacher.php 已经死了:

它检查所请求的图像是否在缓存中找到(它可能是一个文件或其他)如果它不存在那么它会要求它谷歌保存它和echo。

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.

类似于:(伪代码)

     $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.

     }

当然你可以简化一些 googleImageCacher.php中的到期时间

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

这篇关于“cacher layer”用于谷歌生成的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 02:10