#lru-cache not resolving?

3 messages · Page 1 of 1 (latest)

tepid mistBOT
#

Hi @cloud ore. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

The knowledge sources don’t explicitly describe how Nuxt 4 resolves driver: 'lru-cache' in nitro.storage, so I can’t confirm the exact behavior you’re seeing from docs alone.

What we do have is:

  • Nitro/Nuxt storage is powered by unstorage, and the LRU driver is a separate module (unstorage/drivers/lru-cache).[Drivers; LRU cache]

  • When adding storage via a server plugin, the documented pattern is to import the driver yourself and mount it manually, just like in your example:

    import redisDriver from 'unstorage/drivers/redis'
    
    export default defineNitroPlugin(() => {
      const storage = useStorage()
      const driver = redisDriver({ /* options */ })
      storage.mount('redis', driver)
    })
    

    [Server storage]

This suggests that the “safe” and documented way to use non‑default drivers (Redis, LRU, etc.) is exactly what you did: import the driver and mount it in a Nitro plugin.

The docs do not show any example where driver: 'lru-cache' (as a plain string) is auto‑resolved by Nuxt/Nitro, and they don’t mention any built‑in aliasing for that name. [Drivers; LRU cache] Because of that, I can’t confirm that driver: 'lru-cache' is supposed to work without an explicit import, and your observation that it only behaves as LRU after mounting via plugin is consistent with the documented pattern.

So, based on the available docs:

#
  • Your plugin approach is correct and aligned with how other custom storage drivers are wired in.
  • There is no explicit documentation confirming that driver: 'lru-cache' should be auto‑resolved, so if it doesn’t work, that’s not contradicted by the current docs.

If you want a fully “by‑the‑book” setup, I’d keep using the explicit lruCacheDriver import and storage.mount('cache', lruCacheDriver({ max: 100 })) pattern you already have.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: