1

In Drupal 6, I used to be able to look up the number of items via {cache_MODULENAME} table direct in SQL. Is there any way to look it up via the cache API?

  • Might be wrong but I would guess not, because that sort of information isn't typically useful for an application to know. What do you plan to do with the info once you have it? Maybe there are other ways around the problem – Clive Apr 29 '16 at 11:04
  • I had a display in my custom module's admin interface showing the administrator how many items where current in cache with an option to reset. But I can live without it I guess. – Nic Apr 29 '16 at 19:55
4

Given the interface provided for cache backends (CacheBackendInterface), you cannot.

It doesn't expose a method that returns the number of items in the case, which would have made things easier for your use case. There could be a cache backend with a method to count the number of items in the cache, but since it is not part of CacheBackendInterface, that would not be a method you find in every cache backend.
Since CacheBackendInterface doesn't expose any method to know the database table used for cache bins, you should assume some implementation details, and that those details are never changed. If you make assumptions about those implementation details, you can use a SQL query to count the number of items contained in a cache bin. Keep in mind that a cache backend could not use a database table at all, such as in the case of the ApcuBackend class.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.