Skip to content

Latest commit

 

History

History
38 lines (30 loc) · 820 Bytes

CACHE.MD

File metadata and controls

38 lines (30 loc) · 820 Bytes

Cache

Cache the response of the route using a cache rule to define the key.

Definition

#[Cache(CacheRule $cacheRule)]
  • $cacheRule - The cache rule defines how the cache key is generated.

Targets

  • Attribute::TARGET_METHOD

Example

Code:

    #[Method(HttpMethod::GET)]
    #[Path('/cache/{cacheId}')]
    #[Cache(new CacheRule())]
    public function simpleGetWithCacheRule(
        #[PathParameter('cacheId')] int $cacheId
    ): ResponseBuilder {
        return (new ResponseBuilder())
            ->setData($cacheId)
            ->setContentType(MediaType::APPLICATION_JSON)
            ->setHttpStatusCode(HttpStatusCode::HTTP_OK);
    }

cURL:

curl --request POST \ 
    --location 'http://localhost/cache/123' \
    --header 'Content-Type: application/json'