@@ -23,7 +23,7 @@ class Query
2323 */
2424 public function __construct (
2525 protected Model $ model ,
26- protected Repository $ cache ,
26+ protected Repository $ repository ,
2727 ) {}
2828
2929 /**
@@ -39,7 +39,7 @@ public function find(?string $id, int $chunk = 1000): ?Model
3939 return $ this ->whereKey ($ id )->first ($ chunk );
4040 }
4141
42- if (! $ this ->cache ->exists ($ hash = $ this ->model ->getBaseHashWithKey ($ id ))) {
42+ if (! $ this ->repository ->exists ($ hash = $ this ->model ->getBaseHashWithKey ($ id ))) {
4343 return null ;
4444 }
4545
@@ -232,7 +232,7 @@ public function each(Closure $callback, int $chunk = 1000): void
232232 */
233233 public function chunk (int $ count , Closure $ callback ): void
234234 {
235- foreach ($ this ->cache ->chunk ($ this ->getQuery (), $ count ) as $ chunk ) {
235+ foreach ($ this ->repository ->chunk ($ this ->getQuery (), $ count ) as $ chunk ) {
236236 $ models = $ this ->model ->newCollection ();
237237
238238 foreach ($ chunk as $ hash ) {
@@ -251,7 +251,7 @@ public function chunk(int $count, Closure $callback): void
251251 protected function newModelFromHash (string $ hash ): Model
252252 {
253253 return $ this ->model ->newFromBuilder ([
254- ...$ this ->cache ->getAttributes ($ hash ),
254+ ...$ this ->repository ->getAttributes ($ hash ),
255255 $ this ->model ->getKeyName () => $ this ->getKeyValue ($ hash ),
256256 ]);
257257 }
@@ -286,18 +286,34 @@ public function getQuery(): string
286286 return sprintf ('%s:%s ' , $ this ->model ->getHashPrefix (), rtrim ($ pattern , ': ' ));
287287 }
288288
289+ /**
290+ * Get the model instance.
291+ */
292+ public function getModel (): Model
293+ {
294+ return $ this ->model ;
295+ }
296+
297+ /**
298+ * Get the repository instance.
299+ */
300+ public function getRepository (): Repository
301+ {
302+ return $ this ->repository ;
303+ }
304+
289305 /**
290306 * Insert or update a record in the cache.
291307 */
292308 public function insertOrUpdate (string $ hash , array $ attributes = []): void
293309 {
294- $ this ->cache ->transaction (function () use ($ hash , $ attributes ) {
310+ $ this ->repository ->transaction (function () use ($ hash , $ attributes ) {
295311 if (! empty ($ delete = array_keys ($ attributes , null , true ))) {
296- $ this ->cache ->deleteAttributes ($ hash , $ delete );
312+ $ this ->repository ->deleteAttributes ($ hash , $ delete );
297313 }
298314
299315 if (! empty ($ update = array_diff_key ($ attributes , array_flip ($ delete )))) {
300- $ this ->cache ->setAttributes ($ hash , $ update );
316+ $ this ->repository ->setAttributes ($ hash , $ update );
301317 }
302318 });
303319 }
@@ -307,22 +323,22 @@ public function insertOrUpdate(string $hash, array $attributes = []): void
307323 */
308324 public function expire (string $ hash , int $ seconds ): void
309325 {
310- $ this ->cache ->setExpiry ($ hash , $ seconds );
326+ $ this ->repository ->setExpiry ($ hash , $ seconds );
311327 }
312328
313329 /**
314330 * Get a model's time-to-live (in seconds).
315331 */
316332 public function expiry (string $ hash ): ?int
317333 {
318- return $ this ->cache ->getExpiry ($ hash );
334+ return $ this ->repository ->getExpiry ($ hash );
319335 }
320336
321337 /**
322338 * Delete a model from the cache.
323339 */
324340 public function destroy (string $ hash ): void
325341 {
326- $ this ->cache ->delete ($ hash );
342+ $ this ->repository ->delete ($ hash );
327343 }
328344}
0 commit comments