I have implemented your suggestions below but its still doing the same thing.
The changed code looks like this:
require_once('Zend/Loader.php');
Zend_Loader::registerAutoload();
Zend_Loader::loadClass('Zend_Cache');
Zend_Loader::loadClass('Zend_Service_Flickr');
Zend_Loader::loadClasS('Zend_Service_Flickr_ResultSet');
$cache = Zend_Cache::factory('Core', 'Sqlite', $frontendOptions,
$backendOptions);
$flickr = new Zend_Service_Flickr('03ba312703abdbf3cfb59160c8d1a27a');
if(!$results = $cache->load('flickrcache'))
{
$results = $flickr->groupPoolGetPhotos('640118@N24');
$cache->save($results, 'flickrcache');
}
The print_r now shows this when retreived from cache:
Zend_Service_Flickr_ResultSet Object
(
[totalResultsAvailable] => 122
[totalResultsReturned] => 10
[firstResultPosition] => 1
[_results:protected] => DOMNodeList Object
(
)
[_flickr:private] => Zend_Service_Flickr Object
(
[apiKey] =>
[_restClient:protected] => Zend_Rest_Client Object
(
[_data:protected] => Array
(
)
[_uri:protected] => Zend_Uri_Http Object
(
[_username:protected] =>
[_password:protected] =>
[_host:protected] => www.flickr.com
[_port:protected] => 80
[_path:protected] => /services/rest/
[_query:protected] =>
[_fragment:protected] =>
[_regex:protected] => Array
(
[alphanum] => [^\W_]
[escaped] => (?:%[\da-fA-F]{2})
[mark] => [-_.!~*'()\[\]]
[reserved] => [;\/?:@&=+$,]
[unreserved] => (?:[^\W_]|[-_.!~*'()\[\]])
[segment] =>
(?:(?:(?:[^\W_]|[-_.!~*'()\[\]])|(?:%[\da-fA-F]{2})|[:@&=+$,;])*)
[path] =>
(?:\/(?:(?:(?:[^\W_]|[-_.!~*'()\[\]])|(?:%[\da-fA-F]{2})|[:@&=+$,;])*)?)+
[uric] =>
(?:[;\/?:@&=+$,]|(?:[^\W_]|[-_.!~*'()\[\]])|(?:%[\da-fA-F]{2}))
)
[_scheme:protected] => http
)
)
)
[_currentIndex:private] => 0
)
On Wed, Oct 1, 2008 at 8:12 PM, Hector Virgen <djvirgen@gmail.com> wrote:
> You may have to load the class "Zend_Service_Flickr_ResultSet" before
> unloading it from the cache (which unserializes the object). It may help to
> use the autoloader if you can so that you won't have to manually load
> classes.
> http://framework.zend.com/manual/en/zend.loader.html#zend.loader.load.autoload
>
> <?php
> Zend_Loader::registerAutoload();
> ?>
>
> On Wed, Oct 1, 2008 at 8:16 AM, Ian <barnracoon@gmail.com> wrote:
>>
>> Hi,
>>
>> I am trying to use Zend_Cache with Service_Flickr but im getting some
>> weird output.
>>
>> Here is my code:
>> require_once('Zend/Loader.php');
>> Zend_Loader::loadClass('Zend_Cache');
>> Zend_Loader::loadClass('Zend_Service_Flickr');
>>
>>
>> /* Setup cache options */
>> $frontendOptions = array(
>> 'caching' => true,
>> 'lifetime' => 600, // cache lifetime of 10 minutes
>> 'automatic_serialization' => true
>> );
>> $backendOptions = array(
>> 'cache_db_complete_path' => '/tmp/cache.sqlite'
>> );
>>
>> /* Init both vars */
>> $cache = Zend_Cache::factory('Core', 'Sqlite', $frontendOptions,
>> $backendOptions);
>> $flickr = new Zend_Service_Flickr('');
>>
>>
>> if(!$results = $cache->load('flickrcache'))
>> {
>> $results = $flickr->groupPoolGetPhotos('');
>> $cache->save($results, 'flickrcache');
>> }
>>
>> echo '<pre>';
>> print_r($results);
>> echo '</pre>';
>> $num = 0;
>>
>> foreach ($results as $result)
>> {
>> echo '<a href="'.$result->Large->clickUri.'"><img
>> src="'.$result->Square->uri.'" border="0" /></a> ';
>> $num++;
>> if($num == 4) echo '<br />';
>> if($num == 8) break;
>> }
>>
>> The first time the page loads the $results is this:
>> Zend_Service_Flickr_ResultSet Object
>> (
>> [totalResultsAvailable] => 122
>> [totalResultsReturned] => 10
>> [firstResultPosition] => 1
>> [_results:protected] => DOMNodeList Object
>> (
>> )
>>
>> [_flickr:private] => Zend_Service_Flickr Object
>> (
>> [apiKey] =>
>> [_restClient:protected] => Zend_Rest_Client Object
>> (
>> [_data:protected] => Array
>> (
>> )
>>
>> [_uri:protected] => Zend_Uri_Http Object
>> (
>> [_username:protected] =>
>> [_password:protected] =>
>> [_host:protected] => www.flickr.com
>> [_port:protected] => 80
>> [_path:protected] => /services/rest/
>> [_query:protected] =>
>> [_fragment:protected] =>
>> [_regex:protected] => Array
>> (
>> [alphanum] => [^\W_]
>> [escaped] => (?:%[\da-fA-F]{2})
>> [mark] => [-_.!~*'()\[\]]
>> [reserved] => [;\/?:@&=+$,]
>> [unreserved] =>
>> (?:[^\W_]|[-_.!~*'()\[\]])
>> [segment] =>
>> (?:(?:(?:[^\W_]|[-_.!~*'()\[\]])|(?:%[\da-fA-F]{2})|[:@&=+$,;])*)
>> [path] =>
>> (?:\/(?:(?:(?:[^\W_]|[-_.!~*'()\[\]])|(?:%[\da-fA-F]{2})|[:@&=+$,;])*)?)+
>> [uric] =>
>> (?:[;\/?:@&=+$,]|(?:[^\W_]|[-_.!~*'()\[\]])|(?:%[\da-fA-F]{2}))
>> )
>>
>> [_scheme:protected] => http
>> )
>>
>> )
>>
>> )
>>
>> [_currentIndex:private] => 0
>> )
>>
>> Then after the cache it loads as so:
>> __PHP_Incomplete_Class Object
>> (
>> [__PHP_Incomplete_Class_Name] => Zend_Service_Flickr_ResultSet
>> [totalResultsAvailable] => 122
>> [totalResultsReturned] => 10
>> [firstResultPosition] => 1
>> [_results:protected] => DOMNodeList Object
>> (
>> )
>>
>> [_flickr:private] => Zend_Service_Flickr Object
>> (
>> [apiKey] =>
>> [_restClient:protected] => __PHP_Incomplete_Class Object
>> (
>> [__PHP_Incomplete_Class_Name] => Zend_Rest_Client
>> [_data:protected] => Array
>> (
>> )
>>
>> [_uri:protected] => __PHP_Incomplete_Class Object
>> (
>> [__PHP_Incomplete_Class_Name] => Zend_Uri_Http
>> [_username:protected] =>
>> [_password:protected] =>
>> [_host:protected] => www.flickr.com
>> [_port:protected] => 80
>> [_path:protected] => /services/rest/
>> [_query:protected] =>
>> [_fragment:protected] =>
>> [_regex:protected] => Array
>> (
>> [alphanum] => [^\W_]
>> [escaped] => (?:%[\da-fA-F]{2})
>> [mark] => [-_.!~*'()\[\]]
>> [reserved] => [;\/?:@&=+$,]
>> [unreserved] =>
>> (?:[^\W_]|[-_.!~*'()\[\]])
>> [segment] =>
>> (?:(?:(?:[^\W_]|[-_.!~*'()\[\]])|(?:%[\da-fA-F]{2})|[:@&=+$,;])*)
>> [path] =>
>> (?:\/(?:(?:(?:[^\W_]|[-_.!~*'()\[\]])|(?:%[\da-fA-F]{2})|[:@&=+$,;])*)?)+
>> [uric] =>
>> (?:[;\/?:@&=+$,]|(?:[^\W_]|[-_.!~*'()\[\]])|(?:%[\da-fA-F]{2}))
>> )
>>
>> [_scheme:protected] => http
>> )
>>
>> )
>>
>> )
>>
>> [_currentIndex:private] => 0
>> )
>>
>> Is there something I am missing? I cant figure out why its not working
>> or what I need to do to get the results the same.
>>
>> Thanks in advance,
>> Ian
>>
>
>
没有评论:
发表评论