@@ -208,8 +208,10 @@ export class UrlRepository implements UrlRepositoryInterface {
208208 } catch {
209209 // Cache failed, look in database
210210 const redirectDestination = await this . getLongUrlFromDatabase ( shortUrl )
211- this . cacheShortUrl ( shortUrl , redirectDestination ) . catch ( ( error ) =>
212- logger . error ( `Unable to cache short URL: ${ error } ` ) ,
211+ // FIXME: Cache the entire RedirectDestination object once all app
212+ // clients are updated to use the new RedirectDestination type.
213+ this . cacheShortUrl ( shortUrl , redirectDestination . longUrl ) . catch (
214+ ( error ) => logger . error ( `Unable to cache short URL: ${ error } ` ) ,
213215 )
214216 return redirectDestination
215217 }
@@ -533,11 +535,22 @@ export class UrlRepository implements UrlRepositoryInterface {
533535 const redirectDestination = JSON . parse ( cacheLongUrl )
534536 resolve ( redirectDestination )
535537 } catch ( _ ) {
536- reject (
537- new NotFoundError (
538- `longUrl not found in cache:\tshortUrl=${ shortUrl } ` ,
539- ) ,
538+ logger . info (
539+ `Cache lookup returned a string instead of an object:\tshortUrl=${ shortUrl } ` ,
540540 )
541+ resolve ( {
542+ longUrl : cacheLongUrl ,
543+ isFile : false ,
544+ safeBrowsingExpiry : null ,
545+ } )
546+
547+ // FIXME: Throw NotFoundError once all app clients are updated to
548+ // use the new RedirectDestination type.
549+ // reject(
550+ // new NotFoundError(
551+ // `longUrl not found in cache:\tshortUrl=${shortUrl}`,
552+ // ),
553+ // )
541554 }
542555 }
543556 } ) ,
@@ -549,23 +562,35 @@ export class UrlRepository implements UrlRepositoryInterface {
549562 * @param {string } shortUrl Short url.
550563 * @param {string } longUrl Long url.
551564 */
552- private cacheShortUrl : (
553- shortUrl : string ,
554- redirectDestination : RedirectDestination ,
555- ) => Promise < void > = ( shortUrl , redirectDestination ) => {
556- return new Promise ( ( resolve , reject ) => {
557- redirectClient . set (
558- shortUrl ,
559- JSON . stringify ( redirectDestination ) ,
560- 'EX' ,
561- redirectExpiry ,
562- ( err ) => {
565+ private cacheShortUrl : ( shortUrl : string , longUrl : string ) => Promise < void > =
566+ ( shortUrl , longUrl ) => {
567+ return new Promise ( ( resolve , reject ) => {
568+ redirectClient . set ( shortUrl , longUrl , 'EX' , redirectExpiry , ( err ) => {
563569 if ( err ) reject ( err )
564570 else resolve ( )
565- } ,
566- )
567- } )
568- }
571+ } )
572+ } )
573+ }
574+
575+ // FIXME: This is the future implementation of the cacheShortUrl method to be
576+ // used once all app clients are updated to use the new RedirectDestination
577+ // private cacheShortUrl: (
578+ // shortUrl: string,
579+ // redirectDestination: RedirectDestination,
580+ // ) => Promise<void> = (shortUrl, redirectDestination) => {
581+ // return new Promise((resolve, reject) => {
582+ // redirectClient.set(
583+ // shortUrl,
584+ // JSON.stringify(redirectDestination),
585+ // 'EX',
586+ // redirectExpiry,
587+ // (err) => {
588+ // if (err) reject(err)
589+ // else resolve()
590+ // },
591+ // )
592+ // })
593+ // }
569594
570595 /**
571596 * Generates the ranking algorithm to be used in the ORDER BY clause in the
0 commit comments