优化查询代码;增加RSS1

This commit is contained in:
2023-03-02 09:43:25 +08:00
parent 76b123aa53
commit 138708182b
6 changed files with 138 additions and 7 deletions

View File

@@ -9,6 +9,7 @@
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
use app\common\tools\Rss;
use app\common\tools\Sitemap;
use app\Request;
use think\facade\Cache;
@@ -27,7 +28,6 @@ Route::rule('/sitemap.xml', function (Request $request) {
if (!empty($if_not_match)) {
if ($if_not_match == $last_etag) {
Log::debug('sitemap go for etag cache');
return xml('', 304)->eTag($last_etag);
}
}
@@ -41,3 +41,30 @@ Route::rule('/sitemap.xml', function (Request $request) {
return xml($content)->eTag($last_etag);
});
Route::rule('/rss1.xml', function (Request $request) {
$cache_key = 'rss1_cache_key';
$last_etag = Cache::get($cache_key);
if (!empty($cache_key)) {
$if_not_match = $request->header('If-None-Match');
if (!empty($if_not_match)) {
if ($if_not_match == $last_etag) {
return xml('', 304)->eTag($last_etag);
}
}
}
$content = Rss::initRss1();
$last_etag = md5($content);
Cache::set($cache_key, $last_etag);
return xml($content)->eTag($last_etag);
});