Dev-story #1 – Bplus Tree.

The Story

Recently I was forced to change from free of charge (yahoo finance API) service to a payed one.

As I was quite lazy person my solution was lacking any type of data caching or data base storage.

Everything was done by fetching the data from API. This type of solution quite didn’t hit the mark even with 100 . 000 request per day offered by current service. (by couple of users and deep simulation we could hit this threshold within couple of hours)

As for now deadlines rushing me and I don’t have proper time to invent fancy caching + update mechanics. So I though why not give a shot some easy type caching mechanics like bpluss tree ?

Well, I’m bad with algorithms and all the deep knowledge behind binary trees. I just want a kind of storage (as simple as possible) with data on drive so I could end a session and get back to it after a time within LifeCycle of my application. After my application was closed the cache have to be empty again.

Bplus Tree in C# Nuget:


Set it up:

Simple quick setup like this.

Custom serialize for more complex object than strings.

Create file if needed – why not ?

File in the %temp%.

So this should work ? Well yes, until I realize that I’m loosing my cache after dispose.

Below code would fail on assert, why ?

Well I get null values inside my dataFromTree.

But why ? Is it an issue with bplus-tree ? Not really.

If the Key is within this dictionary why it has corrupted values ?

Tear Down.

I just make sure that bplus working with primitives values like <string,string>

Works without an issue. Ok so maybe my ProtobuffSerializer ?

Well yes. I forgot to add quite important attributes which makes serialize to works correctly.

This is the correct version:

[ProtoContract] (not a [DataContract] which I use 🙂 )

[ProtoMember] on the field to parse.

This object is quite flat but keep in mind you will need to spread this attributes around if you have more complex structures.

Dodaj komentarz

Twój adres email nie zostanie opublikowany. Pola, których wypełnienie jest wymagane, są oznaczone symbolem *