@@ -351,6 +351,33 @@ protected function responseFromCache(): ?Response
351
351
return null ;
352
352
}
353
353
354
+ /**
355
+ * Return cache key string based on this class, URL, and request body
356
+ * @return string
357
+ */
358
+ public function cacheKey (): string
359
+ {
360
+ return hash (
361
+ 'sha256 ' ,
362
+ json_encode ([
363
+ self ::class,
364
+ $ this ->getURL (),
365
+ $ this ->encodeBody (),
366
+ config ('api-request.cache_key_seed ' , 'v2024.8.6 ' ),
367
+ ]),
368
+ );
369
+ }
370
+
371
+ public function canBeFulfilledByCache (): bool
372
+ {
373
+ return Cache::tags ($ this ->cacheTags )->has ($ this ->cacheKey ());
374
+ }
375
+
376
+ public function isFromCache (): bool
377
+ {
378
+ return $ this ->responseIsFromCache ;
379
+ }
380
+
354
381
/**
355
382
* For caching the response, how long should the cache be valid?
356
383
* By default, this is one day. To customize, override this method.
@@ -398,6 +425,19 @@ public function getLastLogContents(): string
398
425
return LogFile::disk ()->get ($ this ->getLastLogFile ());
399
426
}
400
427
428
+ /**
429
+ * Get the filename for the last run of this instance of this request.
430
+ * If the last sync or async was a cache hit, this will return the original log of the request that was cached
431
+ * @throws DomainException if this instance has never logged (could mean never run, or $shouldLog is false)
432
+ */
433
+ public function getLastLogFile (): string
434
+ {
435
+ if (!$ this ->sentLogs ) {
436
+ throw new DomainException ('No log files have been saved by this instance. ' );
437
+ }
438
+ return Str::finish ($ this ->getLogFolder (), '/ ' ) . Arr::last ($ this ->sentLogs );
439
+ }
440
+
401
441
/**
402
442
* Can be overridden by children or trait to parse the body in a known format (e.g. JSON or XML)
403
443
* @param string $responseString
@@ -442,36 +482,6 @@ public function getResponse(): ?Response
442
482
return $ this ->response ;
443
483
}
444
484
445
- /**
446
- * Return cache key string based on this class, URL, and request body
447
- * @return string
448
- */
449
- public function cacheKey (): string
450
- {
451
- return hash (
452
- 'sha256 ' ,
453
- json_encode ([
454
- self ::class,
455
- $ this ->getURL (),
456
- $ this ->encodeBody (),
457
- config ('api-request.cache_key_seed ' , 'v2024.8.6 ' ),
458
- ]),
459
- );
460
- }
461
-
462
- public function canBeFulfilledByCache (): bool
463
- {
464
- return Cache::tags ($ this ->cacheTags )->has ($ this ->cacheKey ());
465
- }
466
-
467
- public function getLastLogFile (): string
468
- {
469
- if (!$ this ->sentLogs ) {
470
- throw new DomainException ('No log files have been saved by this instance. ' );
471
- }
472
- return Str::finish ($ this ->getLogFolder (), '/ ' ) . Arr::last ($ this ->sentLogs );
473
- }
474
-
475
485
/**
476
486
* Change the timeout of this request. This is the preferred way to override the default,
477
487
* even in the constructor of a custom class I think this is much more expressive than a numeric constant
@@ -482,8 +492,4 @@ public function setTimeout(CarbonInterval $interval): void
482
492
$ this ->guzzleOptions [RequestOptions::TIMEOUT ] = $ interval ->totalSeconds ;
483
493
}
484
494
485
- public function isFromCache (): bool
486
- {
487
- return $ this ->responseIsFromCache ;
488
- }
489
495
}
0 commit comments