Skip to content

feat(cache): add device-detector cache option to improve performance#19

Merged
pataar merged 3 commits into
pataar:mainfrom
BrianHigby:feat/device-detector-persistent-laravel-cache
May 6, 2026
Merged

feat(cache): add device-detector cache option to improve performance#19
pataar merged 3 commits into
pataar:mainfrom
BrianHigby:feat/device-detector-persistent-laravel-cache

Conversation

@BrianHigby
Copy link
Copy Markdown

Closes #18

Summary

Adds an opt-in cache.device-detector config option (default false) that enables the matomo/device-detector engine's own internal cache via Laravel's cache store. The default is false, so there is no behavior change for existing installs.

Requires a Laravel application context. Do not enable in standalone mode — \DeviceDetector\Cache\LaravelCache uses the Cache facade and will throw without a bootstrapped app.

Checklist

  • composer test passes
  • composer analyse passes (PHPStan level max, zero errors)
  • Test coverage remains at 100%
  • New detection methods have integration tests with real user agent strings
  • New boolean flags include exclusivity assertions (setting one flag doesn't trigger unrelated flags)

Test plan

  • Added test_invoke_with_device_detector_cache_enabled to DeviceDetectorTest
  • Uses Cache::spy() to assert that LaravelCache actually called through to Laravel's cache store

@coveralls
Copy link
Copy Markdown

coveralls commented May 5, 2026

Coverage Status

coverage: 100.0%. remained the same — BrianHigby:feat/device-detector-persistent-laravel-cache into pataar:main

Comment thread src/Stages/DeviceDetector.php Outdated
Comment thread config/browser-detect.php
@pataar
Copy link
Copy Markdown
Owner

pataar commented May 5, 2026

CI is failing

@BrianHigby
Copy link
Copy Markdown
Author

I believe the issue was Cache::spy() on Laravel 11 returns null for all calls, which caused a TypeError in LaravelCache::save() since it expects a bool return. Should be fixed now.

@pataar pataar merged commit c3df5b7 into pataar:main May 6, 2026
11 checks passed
@pataar
Copy link
Copy Markdown
Owner

pataar commented May 6, 2026

Thanks, merged!

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.

Enable persistent Laravel cache for matomo/device-detector

3 participants