samuelnogueira/cache-datastore-newrelic

Reports calls to any psr/simple-cache or psr/cache implementation as a custom New Relic Datastore

0.2.0 2022-05-03 13:31 UTC

This package is auto-updated.

Last update: 2022-06-26 18:45:10 UTC


README

Reports calls to any psr/simple-cache or psr/cache implementation as a custom New Relic Datastore.

Uses the newrelic_record_datastore_segment function to record calls to an unsupported database.

Requirements

Requires New Relic PHP Agent version >= 7.5.0.

Usage

Decorate your existing:

  1. \Psr\Cache\CacheItemPoolInterface
  2. \Psr\SimpleCache\CacheInterface

with respectively:

  1. Samuelnogueira\CacheDatastoreNewrelic\CacheItemPoolDecorator
  2. Samuelnogueira\CacheDatastoreNewrelic\SimpleCacheDecorator

Example with PSR-6: Caching Interface:

use Psr\Cache\CacheItemPoolInterface;
use Samuelnogueira\CacheDatastoreNewrelic\CacheItemPoolDecorator;
use Samuelnogueira\CacheDatastoreNewrelic\DatastoreParams;

/** @var CacheItemPoolInterface $cache */

return new CacheItemPoolDecorator(
    $cache, // your cache adapter
    new DatastoreParams('My Database Product')
);

Example with PSR-16: Common Interface for Caching Libraries (aka Simple Cache):

use Psr\SimpleCache\CacheInterface;
use Samuelnogueira\CacheDatastoreNewrelic\SimpleCacheDecorator;
use Samuelnogueira\CacheDatastoreNewrelic\DatastoreParams;

/** @var CacheInterface $cache */

return new SimpleCacheDecorator(
    $cache, // your cache adapter
    new DatastoreParams('My Database Product')
);