Skip to content

Bug when calling get on only entry in LruObject #32

@tobiasdcl

Description

@tobiasdcl

Hey folks,
first of all thanks for building and maintaining this library ❤️


I stumbled across this issue when investigating failures coming from fastify-rate-limit. I created an issue there because thats where I noticed the impact first.

However based on my current understanding there is an issue in the LruObject implementation - more specifically in the get implementation. Here is a simple test case that I wrote:

  describe('get', () => {
    it('does not overwrite cache.first', async () => {
      cache = new LruObject(5, 500)

      const key = '10.0.0.1'
      const value = 100

      cache.set(key, value)
      expect(cache.first).not.toBeNull()

      cache.get(key)
      expect(cache.first).not.toBeNull()
    })
  })
 FAIL  test/LruObject.spec.js > LruObject > get > does not overwrite cache.first
AssertionError: expected null not to be null
 ❯ test/LruObject.spec.js:77:31
     75| 
     76|       cache.get(key)
     77|       expect(cache.first).not.toBeNull()
       |                               ^
     78|     })
     79| 

Can you confirm that this is indeed not intended?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions