SimplePie Pagination / Cache

房东的猫 提交于 2019-12-03 22:47:19

It stores the cached articles in the /cache directory by default, although their documentation states: "SimplePie includes a caching system which can be used with a file-based cache, database cache or a Memcache-backed cache system.". The default cache duration is one hour. You can override it however with the set_cache_duration function. Make sure you have the cache folder permissions set to at least 755. You may need to increase it to 775 or 777 (but avoid this if at all possible).

As far as the limit on the number of items, are you setting the maximum number of feeds, or the maximum items per feed? For my implementation I limited it to 25 and 3 per feed and it works well. I don't know if there's a default maximum, but there may be and you may have to manually override it. For instance, I have this PHP code on my site:

$max_items_total = 25;     // This sets the maximum number of blogroll items to display
$max_items_per_feed = 3;   // this sets the maximum number of items from each feed to display

$feed = new SimplePie();
$feed->set_feed_url($feed_ary);

// limit the number of items
$feed->set_item_limit($max_items_per_feed);
$feed->enable_cache(true);  // on by default, but I want to be sure
$feed->set_cache_duration(86400);  // set cache duration to 24 hours

foreach ($feed->get_items(0, $max_items_total) as $key=>$item) {
   ...
}

The for loop gets items 1 through 25 for me. You could use a similar method for pagination.

I'm also having issues with caching, and would also appreciate some more info from others.

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