core.memoize

snapshot assumes too much about a CacheProtocol implementation

Details

  • Type: Defect Defect
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Patch:
    Code and Test
  • Approval:
    Accepted

Description

I believe this line https://github.com/clojure/core.memoize/blob/9bdf608af8bbf4a753fc19758446dd821cb45979/src/main/clojure/clojure/core/memoize.clj#L72 assumes too much about implementations of CacheProtocol, namely that they have a field named 'cache'.

The first call to .cache makes sense, since PluggableMemoization has a 'cache' field, but the second call to .cache assumes that any implementation of CacheProtocol that PluggableMemoization wraps will have a 'cache' field.

I ran into this issue when I desired to have a cache that ignores nils, so I attempted to wrap the TTLCache with an implementation of CacheProtocol that would not cache nil values. Calls to snapshot failed since it was trying to access a 'cache' field on my NoNilCache.

I suspect that the outer call to .cache could be replaced with a call to seq, since defcache adds an implementation of seq to each cache implementation which should pull out the keys/values from the cache.

I'd be glad to work up a patch given that I'm not off base in my assumptions.

Activity

Paul Stadig made changes -
Field Original Value New Value
Attachment 3-fix-snapshot-assumptions.diff [ 10743 ]
Paul Stadig made changes -
Fogus made changes -
Patch Code and Test [ 10002 ]
Resolution Completed [ 1 ]
Approval Accepted [ 10005 ]
Assignee Fogus [ fogus ]
Status Open [ 1 ] Resolved [ 5 ]

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: