Skip to content
This repository was archived by the owner on May 28, 2023. It is now read-only.

Commit 58d7c98

Browse files
authored
Merge pull request #583 from didkan/bugfix/attributes-caching
Bugfix: Attributes cache tag and multistore handling
2 parents b75a263 + e6b5259 commit 58d7c98

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [1.12.5] - Unreleased
8+
9+
### Fixed
10+
- Fix caching of attributes. They were missing cache tag, preventing them from being purged correctly and also not separated cache key between multi stores (#583)
11+
712
## [1.12.4] - 2021.01.15
813

914
### Fixed

src/api/attribute/service.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ function transformAggsToAttributeListParam (aggregations): AttributeListParam {
3939
/**
4040
* Returns attributes from cache
4141
*/
42-
async function getAttributeFromCache (attributeCode: string, config) {
42+
async function getAttributeFromCache (attributeCode: string, config, indexName) {
4343
if (config.server.useOutputCache && cache) {
4444
try {
4545
const res = await (cache as TagCache).get(
46-
'api:attribute-list' + attributeCode
46+
'api:' + indexName + ':attribute-list:' + attributeCode
4747
)
4848
return res
4949
} catch (err) {
@@ -56,13 +56,14 @@ async function getAttributeFromCache (attributeCode: string, config) {
5656
/**
5757
* Save attributes in cache
5858
*/
59-
async function setAttributeInCache (attributeList, config) {
59+
async function setAttributeInCache (attributeList, config, indexName) {
6060
if (config.server.useOutputCache && cache) {
6161
try {
6262
await Promise.all(
6363
attributeList.map(attribute => (cache as TagCache).set(
64-
'api:attribute-list' + attribute.attribute_code,
65-
attribute
64+
'api:' + indexName + ':attribute-list:' + attribute.attribute_code,
65+
attribute,
66+
['attribute']
6667
))
6768
)
6869
} catch (err) {
@@ -90,7 +91,7 @@ async function list (attributesParam: AttributeListParam, config, indexName: str
9091

9192
// here we check if some of attribute are in cache
9293
const rawCachedAttributeList = await Promise.all(
93-
attributeCodes.map(attributeCode => getAttributeFromCache(attributeCode, config))
94+
attributeCodes.map(attributeCode => getAttributeFromCache(attributeCode, config, indexName))
9495
)
9596

9697
const cachedAttributeList = rawCachedAttributeList
@@ -125,7 +126,7 @@ async function list (attributesParam: AttributeListParam, config, indexName: str
125126
const fetchedAttributeList = get(response.body, 'hits.hits', []).map(hit => hit._source)
126127

127128
// save atrributes in cache
128-
await setAttributeInCache(fetchedAttributeList, config)
129+
await setAttributeInCache(fetchedAttributeList, config, indexName)
129130

130131
// cached and fetched attributes
131132
const allAttributes = [

0 commit comments

Comments
 (0)