Skip to content

Commit

Permalink
Add cache TTL
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenvanassche committed Dec 1, 2023
1 parent 0ccf1f4 commit fcd5778
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/ContentApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class ContentApi
{
const BASE_URL = 'https://content.spatie.be/api';

const CACHE_TTL = 5 * 60;

public static function getPosts(string $product, int $page = 1, int $perPage = 20, string $sort = '-date', string $theme = 'github-light', array $filters = []): Paginator
{
$response = Http::get(static::BASE_URL.'/collections/posts/entries', [
Expand Down Expand Up @@ -51,7 +53,7 @@ public static function getPosts(string $product, int $page = 1, int $perPage = 2
]
);

Cache::put("posts-{$product}-{$page}-{$perPage}-{$sort}", $posts);
Cache::put("posts-{$product}-{$page}-{$perPage}-{$sort}", $posts, self::CACHE_TTL);

return $posts;
}
Expand All @@ -78,7 +80,7 @@ public static function getPost(string $product, string $slug, string $theme = 'g

$post = Post::fromResponse($postData);

Cache::put("post-{$product}-{$slug}", $post);
Cache::put("post-{$product}-{$slug}", $post, self::CACHE_TTL);

return $post;
}
Expand Down

0 comments on commit fcd5778

Please sign in to comment.