Commit 1ed5734 1 parent eaca1e0 commit 1ed5734 Copy full SHA for 1ed5734
File tree 1 file changed +14
-4
lines changed
packages/bentocache/src/cache/stack
1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -117,12 +117,22 @@ export class CacheStack extends BaseDriver {
117
117
value,
118
118
logicalExpiration : options . logicalTtlFromNow ( ) ,
119
119
}
120
- const item = this . options . serializer . serialize ( rawItem )
121
120
122
- this . l1 ?. set ( key , this . options . serializeL1 ? item : rawItem , options )
123
- await this . l2 ?. set ( key , item , options )
124
- await this . publish ( { type : CacheBusMessageType . Set , keys : [ key ] } )
121
+ /**
122
+ * Store raw or serialized value in the local cache based on the serializeL1 option
123
+ */
124
+ const l1Item = this . options . serializeL1 ? this . options . serializer . serialize ( rawItem ) : rawItem
125
+ this . l1 ?. set ( key , l1Item , options )
126
+
127
+ /**
128
+ * Store the serialized value in the remote cache
129
+ */
130
+ if ( this . l2 ) {
131
+ const l2Item = this . options . serializeL1 ? l1Item : this . options . serializer . serialize ( rawItem )
132
+ await this . l2 ?. set ( key , l2Item as any , options )
133
+ }
125
134
135
+ await this . publish ( { type : CacheBusMessageType . Set , keys : [ key ] } )
126
136
this . emit ( cacheEvents . written ( key , value , this . name ) )
127
137
return true
128
138
}
You can’t perform that action at this time.
0 commit comments