# spatie/once

A magic memoization function

Repository: https://github.com/spatie/once
Canonical: https://ross.abutalabs.com/products/spatie-once
Homepage: https://spatie.be/opensource
Language: PHP
License: MIT
License Family: permissive
Topics: php, cache, performance, magic
Last push: 2026-07-09T10:50:27+00:00

## Health v2 (maintenance only)
Score: 70/100 (v2, computed 2026-09-03T02:20:16.233290+00:00)
- activity 91, release rhythm 26, longevity 100
- inputs: {"age_days": 3587, "days_push": 55, "days_rel": 281, "gap_med": null, "n_releases_24m": 1}
- flags: none
- formula: round(0.45*activity + 0.35*rhythm + 0.20*longevity); archived -> min(score, 10)

## Adoption (not part of the score)
Stars 1446, forks 62 (observed 2026-08-28T04:04:45.275374+00:00)

## What it is
A small PHP package providing a magic `once()` memoization function that caches a callable's result per object instance and argument combination using PHP 8 WeakMaps. It ensures expensive computations run only once per request lifecycle.

## Use cases
- memoize expensive method calls in php
- cache a function result per object instance
- avoid recomputing values within the same request
- memoize static methods with argument-specific results
- run a callable only once per argument combination

## When to choose
- you need lightweight per-object memoization in PHP 8+
- you want results cached only for the current request without a global cache
- you need argument-aware memoization including static contexts

## When to avoid
- you need persistent or cross-request caching (use Redis, APCu, or Laravel cache)
- you target PHP versions older than 8.0
- you need cache invalidation or TTL semantics

## Facets
- artifact type: library
- maturity: stable
- function: caching
- domain: developer-tools, performance
- platform: php
- tags: memoization, weakmap, per-request-cache

## Member repositories
- spatie/once (main) score 70

## Provenance
- Observed fields: from GitHub, fetched 2026-08-28T04:04:45.275374+00:00.
- Health v2: computed from the inputs above; adoption is never an input.
- Inferred fields (summary, facets, guidance): AI-extracted, prompt v1, taxonomy v1, on 2026-08-30T04:36:11.482889+00:00, confidence not recorded.
  - readme: https://github.com/spatie/once (fetched 2026-08-28T04:04:45.275374+00:00, sha edb18e7db8cb)
  - homepage: https://spatie.be/opensource (fetched 2026-08-29T11:46:03.122706+00:00, sha 4a0ae7f7c9b6)
  - site_page: https://spatie.be/docs (fetched 2026-08-29T11:46:03.125594+00:00, sha 08e024d86d95)
  - site_page: https://spatie.be/about-us (fetched 2026-08-29T11:46:03.127767+00:00, sha d3cb88e4b34c)
- Data as of 2026-08-30T08:39:29.467469+00:00.
