b2c-custom-caches
БесплатноБез исполняемых скриптовНе проверенImplement custom caching with CacheMgr, caches.json definitions, and cache region configuration. Use this skill whenever the user needs to cache expensive…
от SalesforceCommerceCloud★ 58 звёзд на GitHubОб этом скилле
B2C Custom Caches
Custom caches improve code performance by storing data that is expensive to calculate, takes a long time to retrieve, or is accessed frequently. Caches are defined in JSON files within cartridges and accessed via the Script API.
When to Use Custom Caches
| Use Case | Example |
|---|---|
| Expensive calculations | Check if any variation product is on sale for base product display |
| External system responses | Cache in-store availability or prices from external APIs |
| Configuration settings | Store configuration data from JSON files or external sources |
| Frequently accessed data | Product attributes, category data, site preferences |
Limitations
| Constraint | Value |
|---|---|
| Total memory per app server | ~20 MB for all custom caches |
| Max caches per code version | 100 |
| Max entry size | 128 KB |
| Supported value types | Primitives, arrays, plain objects, null (not undefined) |
| Cross-server sync | None (caches are per-application-server) |
Defining a Custom Cache
File Structure
my_cartridge/
├── package.json # References caches.json
└── caches.json # Cache definitions
package.json
Add a caches entry pointing to the cache definition file:
{
"name": "my_cartridge",
"caches": "./caches.json"
}
caches.json
Define caches with unique IDs and optional expiration:
{
"caches": [
{
"id": "ProductAttributeCache"
},
{
"id": "ExternalPriceCache",
"expireAfterSeconds": 300
},
{
"id": "SiteConfigCache",
"expireAfterSeconds": 60
}
]
}
| Property | Required | Description |
|---|---|---|
id |
Yes | Unique ID across all cartridges in code version |
expireAfterSeconds |
No | Maximum seconds an entry is retained |
Using Custom Caches
Script API Classes
| Class | Description |
|---|---|
dw.system.CacheMgr |
Entry point for accessing defined caches |
dw.system.Cache |
Cache instance for storing and retrieving entries |
Basic Usage
var CacheMgr = require('dw/system/CacheMgr');
// Get a defined cache
var cache = CacheMgr.getCache('ProductAttributeCache');
// Get value (returns undefined if not found)
var value = cache.get('myKey');
// Store value directly
cache.put('myKey', { data: 'value' });
// Remove entry
cache.invalidate('myKey');
Recommended Pattern: get with Loader
Use get(key, loader) to automatically populate the cache on miss:
var CacheMgr = require('dw/system/CacheMgr');
var Site = require('dw/system/Site');
var cache = CacheMgr.getCache('SiteConfigCache');
// Loader function called only on cache miss
var config = cache.get(Site.current.ID + '_config', function() {
// Expensive operation - only runs if not cached
return loadConfigurationFromFile(Site.current);
});
Scoped Cache Keys
Include scope identifiers in keys to separate entries by context:
var CacheMgr = require('dw/system/CacheMgr');
var Site = require('dw/system/Site');
var cache = CacheMgr.getCache('ProductCache');
// Site-scoped key
var siteKey = Site.current.ID + '_' + productID;
var productData = cache.get(siteKey, loadProductData);
// Catalog-scoped key
var catalogKey = 'catalog_' + catalogID + '_' + productID;
var catalogData = cache.get(catalogKey, loadCatalogData);
// Locale-scoped key
var localeKey = request.locale + '_' + contentID;
var content = cache.get(localeKey, loadLocalizedContent);
Cache Methods
| Method | Description |
|---|---|
get(key) |
Returns cached value or undefined |
get(key, loader) |
Returns cached value or calls loader, stores result |
put(key, value) |
Stores value directly (overwrites existing) |
invalidate(key) |
Removes entry for key |
Best Practices
Do
- Use
get(key, loader)pattern for automatic population - Include scope (site, catalog, locale) in cache keys
- Set appropriate
expireAfterSecondsfor time-sensitive data - Handle cache misses gracefully (data may be evicted anytime)
- Use descriptive cache IDs
Don't
- Include personal user data in cache keys (keys may appear in logs)
- Store Script API objects (only primitives and plain objects)
- Rely on cache entries existing (no persistence guarantee)
- Expect cross-server cache synchronization
- Store
undefinedvalues (usenullinstead)
Cache Invalidation
Caches are automatically cleared when:
- Any file in the active code version changes
- A new code version is activated
- Data replication completes
- Code replication completes
Manual invalidation only affects the current application server:
var cache = CacheMgr.getCache('MyCache');
// Invalidate single entry (current app server only)
cache.invalidate('myKey');
// Storing undefined has same effect as invalidate
cache.put('myKey', undefined);
Common Patterns
Caching E
Установить b2c-custom-caches в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл b2c-custom-caches?
Implement custom caching with CacheMgr, caches.json definitions, and cache region configuration. Use this skill whenever the user needs to cache expensive computations or API responses server-side, define cache regions with TTL and size limits, invalidate cache entries, or debug disappearing cache data. Also use when optimizing script performance with application-level caching -- even if they just say 'cache this data' or 'my cached values keep disappearing'.
Как установить скилл b2c-custom-caches?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл b2c-custom-caches запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic