strapi-nextgen-framework
Version:
Production-ready, type-safe framework bridging Strapi v4 CMS and Next.js 14+ App Router with automatic cache management, Error Boundaries, and SEO optimization
48 lines • 1.55 kB
JavaScript
;
/**
* Cache tag generation utilities
* Generates consistent cache tags for Next.js revalidation
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseCacheTag = exports.generateCacheTag = void 0;
/**
* Generates a cache tag for a Strapi resource
*
* @param type - Resource type (page, collection, global)
* @param identifier - Resource identifier (slug, collection name, global name)
* @param locale - Optional locale for i18n
* @returns Cache tag string
*
* @example
* ```typescript
* generateCacheTag('page', 'home') // 'strapi_page_home'
* generateCacheTag('page', 'about', 'fr') // 'strapi_page_about_fr'
* generateCacheTag('collection', 'blogPosts') // 'strapi_collection_blogPosts'
* generateCacheTag('global', 'header') // 'strapi_global_header'
* ```
*/
function generateCacheTag(type, identifier, locale) {
const baseTag = `strapi_${type}_${identifier}`;
return locale ? `${baseTag}_${locale}` : baseTag;
}
exports.generateCacheTag = generateCacheTag;
/**
* Parses a cache tag back into its components
* Useful for debugging and tag mapping
*
* @param tag - Cache tag string
* @returns Parsed tag components or null if invalid
*/
function parseCacheTag(tag) {
const match = tag.match(/^strapi_(page|collection|global)_([^_]+)(?:_(.+))?$/);
if (!match) {
return null;
}
return {
type: match[1],
identifier: match[2],
locale: match[3],
};
}
exports.parseCacheTag = parseCacheTag;
//# sourceMappingURL=cache-tags.js.map