Re: Implementing a cache

2016-07-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/2/16 8:10 AM, qznc wrote: I want to implement some caching for HTTP GET requests. Basically a map of URL to content. A cache needs some additional meta data (size, age, etc). There seem to be two basic data structures available: Associative array (AA) or red black tree (RBT). With AA cache

Re: Implementing a cache

2016-07-03 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Saturday, 2 July 2016 at 12:10:28 UTC, qznc wrote: With AA cache eviction is inefficient. It requires to sort the keys of the AA with respect to a field in the value. Stack No, you just need the hash of the key in the object for many types of hash-tables. There are many solutions, but here

Re: Implementing a cache

2016-07-03 Thread Jack Stouffer via Digitalmars-d-learn
On Sunday, 3 July 2016 at 17:15:32 UTC, Lodovico Giaretta wrote: To avoid the ~= operator and reallocations of the cache array, you could impose a max number of cache entries, preallocate the array and use it as a circular buffer. Here's a simple ring buffer I use, feel free to take it struct

Re: Implementing a cache

2016-07-03 Thread Lodovico Giaretta via Digitalmars-d-learn
On Sunday, 3 July 2016 at 16:03:51 UTC, qznc wrote: On Saturday, 2 July 2016 at 12:21:14 UTC, Lodovico Giaretta wrote: On Saturday, 2 July 2016 at 12:10:28 UTC, qznc wrote: Alternatively, any better idea to implement the cache? I guess there is no off-the-shelf/dub solution. For now, I settle

Re: Implementing a cache

2016-07-03 Thread qznc via Digitalmars-d-learn
On Saturday, 2 July 2016 at 12:21:14 UTC, Lodovico Giaretta wrote: On Saturday, 2 July 2016 at 12:10:28 UTC, qznc wrote: Alternatively, any better idea to implement the cache? I guess there is no off-the-shelf/dub solution. For now, I settled for a sorted array of cache entries plus an AA to

Re: Implementing a cache

2016-07-02 Thread Lodovico Giaretta via Digitalmars-d-learn
On Saturday, 2 July 2016 at 12:10:28 UTC, qznc wrote: I want to implement some caching for HTTP GET requests. Basically a map of URL to content. A cache needs some additional meta data (size, age, etc). There seem to be two basic data structures available: Associative array (AA) or red black

Implementing a cache

2016-07-02 Thread qznc via Digitalmars-d-learn
I want to implement some caching for HTTP GET requests. Basically a map of URL to content. A cache needs some additional meta data (size, age, etc). There seem to be two basic data structures available: Associative array (AA) or red black tree (RBT). With AA cache eviction is inefficient. It