1515
1616const SERVICE_ID = 'FairPackageManagementRepo ' ;
1717const CONTENT_TYPE = 'application/json+fair ' ;
18+ const CACHE_KEY = 'fair-packages- ' ;
1819const CACHE_LIFETIME = 12 * HOUR_IN_SECONDS ;
1920const RELEASE_PACKAGES_CACHE_KEY = 'fair-release-packages ' ;
2021
@@ -83,7 +84,7 @@ function get_did_hash( string $id ) {
8384 * @return DIDDocument|WP_Error
8485 */
8586function get_did_document ( string $ id ) {
86- $ cached = get_site_transient ( $ id );
87+ $ cached = wp_cache_get ( $ id, ' did-docs ' );
8788 if ( $ cached ) {
8889 return $ cached ;
8990 }
@@ -98,7 +99,7 @@ function get_did_document( string $id ) {
9899 if ( is_wp_error ( $ document ) ) {
99100 return $ document ;
100101 }
101- set_site_transient ( $ id , $ document , CACHE_LIFETIME );
102+ wp_cache_set ( $ id , $ document, ' did-docs ' , CACHE_LIFETIME );
102103
103104 return $ document ;
104105}
@@ -142,8 +143,8 @@ function fetch_package_metadata( string $id ) {
142143 * @return MetadataDocument|WP_Error
143144 */
144145function fetch_metadata_doc ( string $ url ) {
145- $ cache_key = md5 ( $ url );
146- $ response = get_site_transient ( $ cache_key );
146+ $ cache_key = CACHE_KEY . md5 ( $ url );
147+ $ response = wp_cache_get ( $ cache_key, ' metadata-docs ' );
147148
148149 if ( ! $ response ) {
149150 $ response = wp_remote_get ( $ url , [
@@ -158,7 +159,7 @@ function fetch_metadata_doc( string $url ) {
158159 } elseif ( $ code !== 200 ) {
159160 return new WP_Error ( 'fair.packages.metadata.failure ' , __ ( 'HTTP error code received ' , 'fair ' ) );
160161 }
161- set_site_transient ( $ cache_key , $ response , CACHE_LIFETIME );
162+ wp_cache_set ( $ cache_key , $ response, ' metadata-docs ' , CACHE_LIFETIME );
162163 }
163164
164165 return MetadataDocument::from_response ( $ response );
0 commit comments