By default, only values that can be serialized can be cached.
Can you call `(serialize ....)` on one of these structs?

If that is the problem, one fix is to add the `prop:serializable` property
to the struct definition.
http://docs.racket-lang.org/reference/serialization.html?q=prop%3Aserializable#%28def._%28%28lib._racket%2Fprivate%2Fserialize..rkt%29._prop~3aserializable%29%29

Either way, another fix is to define functions that convert instances of
the struct to s-expressions & use the #:read and #:write options for
with-cache

(define (frame->sexp f) ....)

(define (sexp->frame s) ....)

(with-cache "data.rktd"

  #:write frame->sexp

  #:read sexp->frame

  (lambda () ....))


On Wed, Nov 23, 2016 at 5:46 AM, Alex Harsanyi <alexharsa...@gmail.com>
wrote:

> Hi Ben,
>
> What types of values can be cached by with-cache?
>
> I tried to use it with a data-frame object I use in my application (wanted
> to check if it is faster to retrieve it from the filesystem than the
> database), but unfortunately it failed with:
>
> ; with-cache: Internal error: failed to make writable value from result
> '#(struct:object:data-frame% ...)'
>
> The object itself is essentially a collection of large (about 10000 items)
> vectors (about 30 of them) plus some metadata.
>
> Thanks,
> Alex.
>
> On Wednesday, November 23, 2016 at 1:11:27 PM UTC+8, Ben Greenman wrote:
> > with-cache is a small package for saving the results of an expression to
> the filesystem
> >
> >
> >
> > #lang racket/base
> > (require pict with-cache)
> >
> >
> > (define (get-fish)
> >   (with-cache (cachefile "stdfish.rktd")
> >     (λ () (standard-fish 100 50))))
> >
> >
> > (get-fish) ;; Builds a fish
> > (get-fish) ;; Reads a fish from "./compiled/with-cache/stdfish.rktd"
> >
> >
> >
> > Run the above with `racket -W info@with-cache file.rkt` to see when
> cache files get written and read.
> >
> >
> > By default, cached data is serialized, written in fasl format, and
> invalidated if read by a different version of the with-cache library. You
> can override all these options; the docs should explain how.
> >
> >
> >
> > Docs (latest update is yet to sync on the package server):
> > http://docs.racket-lang.org/with-cache/index.html
> >
> >
> >
> > Code:
> > https://github.com/bennn/with-cache
> >
> >
> >
> > History:
> > I started writing this code while working on a Scribble document with
> lots of picts in it. (Most of the picts were made by plot. Tweaking plot
> parameters led to the *current-cache-keys* parameter.)
> > William Bowman encouraged me to put an early version of this code on the
> package server.
> > Leif Andersen pointed out LOTS of places where the original code needed
> to improve.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to