taoensso / nippy

The fastest serialization library for Clojure
https://www.taoensso.com/nippy
Eclipse Public License 1.0
1.04k stars 60 forks source link

Serializing clojure.core.cache.TTLCache failed #124

Closed stefan-toubia closed 3 years ago

stefan-toubia commented 4 years ago

I'm attempting to upgrade nippy from 2.8.0 to 2.15.0-RC1. Previously we were serializing our cache to be saved to a file. After updating I'm now getting this exception:

java.lang.NoSuchFieldException: ttl-ms
        at java.lang.Class.getField(Class.java:1703)
        at taoensso.nippy$eval66813$fn__66814$fn__66815$fn__66816.invoke(nippy.clj:943)
        at taoensso.nippy$eval66813$fn__66814$fn__66815.invoke(nippy.clj:941)
        at clojure.lang.PersistentVector.reduce(PersistentVector.java:343)
        at clojure.core$reduce.invokeStatic(core.clj:6827)
        at clojure.core$reduce.invoke(core.clj:6810)
        at taoensso.nippy$eval66813$fn__66814.invoke(nippy.clj:941)
        at taoensso.nippy$eval66497$fn__66498$G__66488__66505.invoke(nippy.clj:332)
        at taoensso.nippy$eval66552$fn__66553.invoke(nippy.clj:349)
        at taoensso.nippy$eval66525$fn__66526$G__66516__66533.invoke(nippy.clj:333)
        at taoensso.nippy$freeze$fn__66849.invoke(nippy.clj:1025)
        at taoensso.nippy$freeze.invokeStatic(nippy.clj:1025)
        at taoensso.nippy$freeze.invoke(nippy.clj:1001)
        at taoensso.nippy$freeze.invokeStatic(nippy.clj:1004)
        at taoensso.nippy$freeze.invoke(nippy.clj:1001)

We're setting up our cache like this

(defn- create-cache [data]
  (cache/ttl-cache-factory (or data {}) :ttl (t/in-millis (t/hours 1))))

(defonce requests-cache (atom (create-cache nil)))

An exception is thrown when attempting to freeze:

(nippy/freeze @requests-cache)

Of course, casting the cache to a PersistentArrayMap works. I'm trying to figure out if I should expect clojure.cache objects to be serializable, or does this require handling as a custom type?

ptaoussanis commented 3 years ago

Hi there! Just checking if this is this still an active issue, or can it be closed? Thanks