@@ -69,13 +69,15 @@ async function getRegistryReleases(
6969 const cacheNamespace : PackageCacheNamespace = `datasource-releases-${ datasource . id } ` ;
7070 const cacheKey = `${ registryUrl } :${ config . packageName } ` ;
7171
72- if ( datasource . caching ) {
72+ const cacheEnabled = ! ! datasource . caching ; // tells if `isPrivate` flag is supported in datasource result
73+ const cacheForced = GlobalConfig . get ( 'cachePrivatePackages' , false ) ; // tells if caching is forced via admin config
74+
75+ if ( cacheEnabled || cacheForced ) {
7376 const cachedResult = await packageCache . get < ReleaseResult > (
7477 cacheNamespace ,
7578 cacheKey ,
7679 ) ;
7780
78- // istanbul ignore if
7981 if ( cachedResult ) {
8082 logger . trace ( { cacheKey } , 'Returning cached datasource response' ) ;
8183 DatasourceCacheStats . hit ( datasource . id , registryUrl , config . packageName ) ;
@@ -90,32 +92,30 @@ async function getRegistryReleases(
9092 res . registryUrl ??= registryUrl ;
9193 }
9294
93- // cache non-null responses unless marked as private
94- if ( res ) {
95- let cachingAllowed = false ;
96-
97- if ( GlobalConfig . get ( 'cachePrivatePackages' , false ) ) {
98- cachingAllowed = true ;
99- }
95+ if ( ! res ) {
96+ return null ;
97+ }
10098
101- if ( datasource . caching && ! res . isPrivate ) {
102- cachingAllowed = true ;
103- }
99+ let cache = false ;
100+ if ( cacheForced ) {
101+ cache = true ;
102+ } else if ( cacheEnabled && ! res . isPrivate ) {
103+ cache = true ;
104+ }
104105
105- if ( cachingAllowed ) {
106- logger . trace ( { cacheKey } , 'Caching datasource response' ) ;
106+ if ( cache ) {
107+ logger . trace ( { cacheKey } , 'Caching datasource response' ) ;
107108
108- // This is meant to be short-lived cache, so we ignore `hardTtlMinutes`
109- // and stick to the `softTtlMinutes` value
110- const { softTtlMinutes : cacheMinutes } = resolveTtlValues (
111- cacheNamespace ,
112- 15 ,
113- ) ;
114- await packageCache . set ( cacheNamespace , cacheKey , res , cacheMinutes ) ;
115- DatasourceCacheStats . set ( datasource . id , registryUrl , config . packageName ) ;
116- } else {
117- DatasourceCacheStats . skip ( datasource . id , registryUrl , config . packageName ) ;
118- }
109+ // This is meant to be short-lived cache, so we ignore `hardTtlMinutes`
110+ // and stick to the `softTtlMinutes` value
111+ const { softTtlMinutes : cacheMinutes } = resolveTtlValues (
112+ cacheNamespace ,
113+ 15 ,
114+ ) ;
115+ await packageCache . set ( cacheNamespace , cacheKey , res , cacheMinutes ) ;
116+ DatasourceCacheStats . set ( datasource . id , registryUrl , config . packageName ) ;
117+ } else {
118+ DatasourceCacheStats . skip ( datasource . id , registryUrl , config . packageName ) ;
119119 }
120120
121121 return res ;
0 commit comments