File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed
packages/bentocache/src/cache/stack Expand file tree Collapse file tree 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 {
117117 value,
118118 logicalExpiration : options . logicalTtlFromNow ( ) ,
119119 }
120- const item = this . options . serializer . serialize ( rawItem )
121120
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+ }
125134
135+ await this . publish ( { type : CacheBusMessageType . Set , keys : [ key ] } )
126136 this . emit ( cacheEvents . written ( key , value , this . name ) )
127137 return true
128138 }
You can’t perform that action at this time.
0 commit comments