Skip to content

Add datetime rounding for @ApiCache to improve cache hits#1

Merged
maikschneider merged 10 commits intomainfrom
copilot/add-datetime-filter-annotation
Mar 26, 2026
Merged

Add datetime rounding for @ApiCache to improve cache hits#1
maikschneider merged 10 commits intomainfrom
copilot/add-datetime-filter-annotation

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 26, 2026

Add @ApiCacheRoundDatetime annotation for datetime filter cache key normalization

When using datetime filters with @ApiCache, clients typically pass the current timestamp, which changes on every request and prevents cache hits. The new @ApiCacheRoundDatetime class-level annotation rounds datetime filter parameter values to a configurable precision (minute, hour, day, or year) before cache key generation, so that requests within the same time window produce identical cache keys.

Features

  • New @ApiCacheRoundDatetime annotation — placed on the entity class alongside @ApiCache
  • Configurable precisionminute, hour (default), day, or year
  • Configurable directionfloor (default, round down) or ceil (round up)
  • Automatic filter variant support — a single parameterName (e.g. "date") applies rounding to date, date[lt], date[gte], etc.
  • Multiple annotations per class — one per datetime parameter
  • Format-preserving — supports Unix timestamps, ISO 8601, and date-only strings; returns rounded values in the same format

Example

/**
 * @ApiCache
 * @ApiCacheRoundDatetime(parameterName="date", precision="hour")
 */
class Event extends AbstractEntity
{
    protected \DateTime $date;
}

Requests with ?date=2025-03-26T09:47:12+00:00 and ?date=2025-03-26T09:12:45+00:00 both round to 2025-03-26T09:00:00+00:00, producing the same cache key.


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Copilot AI and others added 10 commits March 26, 2026 09:25
Create new @ApiCacheRoundDatetime annotation that rounds datetime filter
parameter values to configurable precisions (minute, hour, day, year)
before cache key generation, improving cache hit rates for datetime-based
API queries. Supports floor and ceil rounding directions.

Co-authored-by: maikschneider <696865+maikschneider@users.noreply.github.com>
Agent-Logs-Url: https://github.com/xima-media/t3api_cache/sessions/afd7d73b-38c3-43b9-935d-91d703ae3505
…THOD

The annotation now targets properties and methods instead of the class,
allowing multiple annotations per entity. Each annotation configures
rounding for a single datetime parameter with precision, direction,
and optional parameterName override.

Co-authored-by: maikschneider <696865+maikschneider@users.noreply.github.com>
Agent-Logs-Url: https://github.com/xima-media/t3api_cache/sessions/6c2d48c6-acbe-4974-8a01-e9da35707089
…roperty

When @ApiCacheRoundDatetime is placed on a method with @VirtualProperty
and @SerializedName, the serialized name is automatically used as the
query parameter name. Priority: explicit parameterName > @SerializedName
> @VirtualProperty name > PHP property/method name.

Co-authored-by: maikschneider <696865+maikschneider@users.noreply.github.com>
Agent-Logs-Url: https://github.com/xima-media/t3api_cache/sessions/cdf5ee1d-dd32-4fc6-b42a-8b5cb4d3dde7
…composer.lock

Co-authored-by: maikschneider <696865+maikschneider@users.noreply.github.com>
Agent-Logs-Url: https://github.com/xima-media/t3api_cache/sessions/27fcd744-689a-471d-9a6d-9a0847da91a3
…rName, support filter variants

Co-authored-by: maikschneider <696865+maikschneider@users.noreply.github.com>
Agent-Logs-Url: https://github.com/xima-media/t3api_cache/sessions/34f3bbca-56d0-435b-86ee-fa960cb7aac0
…ed parameterName

Co-authored-by: maikschneider <696865+maikschneider@users.noreply.github.com>
Agent-Logs-Url: https://github.com/xima-media/t3api_cache/sessions/34f3bbca-56d0-435b-86ee-fa960cb7aac0
…e-pass iteration

Co-authored-by: maikschneider <696865+maikschneider@users.noreply.github.com>
Agent-Logs-Url: https://github.com/xima-media/t3api_cache/sessions/34f3bbca-56d0-435b-86ee-fa960cb7aac0
Copilot AI requested a review from maikschneider March 26, 2026 11:28
@maikschneider maikschneider changed the title Move ApiCacheRoundDatetime to class-level annotation with required parameterName and filter variant support Add datetime rounding for @ApiCache to improve cache hits Mar 26, 2026
@maikschneider maikschneider marked this pull request as ready for review March 26, 2026 12:56
@maikschneider maikschneider merged commit f35c904 into main Mar 26, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants