Skip to content
Documentation
Statitics Method

Stats Method

The stats method retrieves detailed statistics about the cache, including the number of cache entries, cache hits, cache misses, and evictions. This information helps in monitoring and analyzing the performance of the cache.

Features

  • Statistics Retrieval: Provides information on cache size, hits, misses, and evictions.
  • Logging: Includes logging for retrieving cache statistics.

Usage

import versedb from 'verse.db';
 
const adapter = new versedb.connect({
  adapter: "cache",
  maxSize: 1000,
  ttl: 3600000, // 1 hour in milliseconds
  devLogs: { enable: false, path: "" },
});
 
async function getCacheStats() {
  const result = await adapter.stats();
  console.log('Cache statistics:', result.results);
}
 
getCacheStats();

Returns

  • A Promise that resolves with an AdapterResults object containing cache statistics.

Example

adapter
  .stats()
  .then((result) => {
    console.log("Cache statistics:", result.results);
  })
  .catch((error) => {
    console.error("Error retrieving cache statistics:", error);
  });

Detailed Explanation

  1. Statistics Data: Provides the following metrics:

    • size: Current number of entries in the cache.
    • hits: Number of cache hits.
    • misses: Number of cache misses.
    • evictions: Number of cache entries evicted due to size constraints.
  2. Logging: Logs the retrieval of cache statistics.

    • Useful for monitoring and performance tuning.

VERSE.DB. Powered by JEDI Studio.