fix: rss & sitemap cache
This commit is contained in:
@@ -13,9 +13,10 @@ export enum RedisItems {
|
||||
Ips = 'ips',
|
||||
}
|
||||
|
||||
export const CacheKeys = Object.freeze({
|
||||
AggregateCatch: 'mx-api-cache:aggregate_catch',
|
||||
SiteMapCatch: 'mx-api-cache:aggregate_sitemap_catch',
|
||||
RSS: 'mx-api-cache:rss',
|
||||
RSSCatch: 'mx-api-cache:rss_catch',
|
||||
} as const)
|
||||
export enum CacheKeys {
|
||||
AggregateCatch = 'mx-api-cache:aggregate_catch',
|
||||
SiteMapCatch = 'mx-api-cache:aggregate_sitemap_catch',
|
||||
SiteMapXmlCatch = 'mx-api-cache:aggregate_sitemap_xml_catch',
|
||||
RSS = 'mx-api-cache:rss',
|
||||
RSSXmlCatch = 'mx-api-cache:rss_xml_catch',
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ export class FeedController {
|
||||
) {}
|
||||
|
||||
@Get('/')
|
||||
@CacheKey(CacheKeys.RSSCatch)
|
||||
@CacheKey(CacheKeys.RSSXmlCatch)
|
||||
@CacheTTL(3600)
|
||||
@HTTPDecorators.Bypass
|
||||
@Header('content-type', 'application/xml')
|
||||
@@ -27,18 +27,20 @@ export class FeedController {
|
||||
await this.aggregateService.buildRssStructure()
|
||||
const { title } = this.configs.get('seo')
|
||||
const { avatar } = await this.configs.getMaster()
|
||||
const now = new Date()
|
||||
const xml = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||
<title>${title}</title>
|
||||
<link href="/atom.xml" rel="self"/>
|
||||
<link href="/feed" rel="self"/>
|
||||
<link href="${xss(url)}"/>
|
||||
<updated>${new Date().toISOString()}</updated>
|
||||
<updated>${now.toISOString()}</updated>
|
||||
<id>${xss(url)}</id>
|
||||
<author>
|
||||
<name>${author}</name>
|
||||
</author>
|
||||
<generator>${'Mix Space CMS'}</generator>
|
||||
<lastBuildDate>${now.toISOString()}</lastBuildDate>
|
||||
<language>zh-CN</language>
|
||||
<image>
|
||||
<url>${xss(avatar)}</url>
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { CacheTTL, Controller, Get, Header } from '@nestjs/common'
|
||||
import { CacheKey, CacheTTL, Controller, Get, Header } from '@nestjs/common'
|
||||
import { minify } from 'html-minifier'
|
||||
import { HTTPDecorators } from '~/common/decorator/http.decorator'
|
||||
import { ApiName } from '~/common/decorator/openapi.decorator'
|
||||
import { CacheKeys } from '~/constants/cache.constant'
|
||||
import { AggregateService } from '../aggregate/aggregate.service'
|
||||
@Controller('sitemap')
|
||||
@ApiName
|
||||
@@ -10,6 +11,7 @@ export class SitemapController {
|
||||
|
||||
@Get('/')
|
||||
@CacheTTL(3600)
|
||||
@CacheKey(CacheKeys.SiteMapXmlCatch)
|
||||
@HTTPDecorators.Bypass
|
||||
@Header('content-type', 'application/xml')
|
||||
async getSitemap() {
|
||||
|
||||
3
src/processors/cache/cache.service.ts
vendored
3
src/processors/cache/cache.service.ts
vendored
@@ -51,9 +51,10 @@ export class CacheService {
|
||||
public clearAggregateCache() {
|
||||
return Promise.all([
|
||||
this.redisClient.del(CacheKeys.RSS),
|
||||
this.redisClient.del(CacheKeys.SiteMapCatch),
|
||||
this.redisClient.del(CacheKeys.RSSXmlCatch),
|
||||
this.redisClient.del(CacheKeys.AggregateCatch),
|
||||
this.redisClient.del(CacheKeys.SiteMapCatch),
|
||||
this.redisClient.del(CacheKeys.SiteMapXmlCatch),
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user