[plt-scheme] Caching database rows

From: Ryan Culpepper (ryanc at ccs.neu.edu)
Date: Sat Mar 8 02:03:48 EST 2008

Henk Boom wrote:
> Hi,
> 
> I am mapping sqlite rows of a certain table onto my own "node" struct
> type, by filling it's fields with information from the database.
> Things get dicey when the records in the database are changed or
> removed: I want to automatically update old node objects when a row in
> the database is modified. To do this, I imagine caching all retrieved
> nodes so that I have access to them when I need to either correct or
> invalidate them. I can think only of the following way to implement
> this:
> 
> A hash-table of integers (row ids) to weak-boxed node structures. I
> would attach wills to the nodes to remove the key-value pair from the
> hash-table when they are no longer referenced.

You could also set up a thread that periodically vacuums the hash-table, 
removing any keys that map to empty weak-boxes. That removes the need 
for will executors.

Ryan


> 
> This sounds to me like a complicated solution to what should be a
> simple problem. Is there a nicer way to accomplish this?
> 
> Please let me know if my explanation is incoherent, it seems I've been
> mulling this over long enough that I've lost the ability to see what
> parts are obvious or not.
> 
>     Henk
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.