Skip to content

Conversation

@wangkuiyi
Copy link
Contributor

No description provided.

pngFile := path.Join(*dir, id) + ".png"

if _, e := os.Stat(pngFile); os.IsNotExist(e) {
// TODO(yi): Here we adopt an unlimted-size disk-based cache. We should
Copy link

@helinwang helinwang Nov 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another approach could be create a tmp file and and delete it after exec graphviz binary. Remove the tmp file and do something like following:

type entry struct {
md5 string
png []byte
}
var cache []entry
cache = append(cache, entry{md5,png})
if len(cache) > 100 {
cache = cache[1:]
}

not LRU cache but seems sufficient and simple enough. (linear search time but seems fine for this small program, not LRU but seems ok as well :))
This way will leave no trace on harddisk.
But the harddisk cache is fine as well.

Copy link
Contributor Author

@wangkuiyi wangkuiyi Nov 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean a random-deletion cache other than LRU cache?

I love this idea. How about we implement it in a next PR?

Copy link

@helinwang helinwang Nov 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will delete cache entry by earliest created one, but not necessarily Least Recent Used one (e.g., LRU cache will not delete earliest created one if it's recently used.)
Sure, LGTM!

@helinwang
Copy link

LGTM!

@wangkuiyi wangkuiyi merged commit 65c5ecb into develop Nov 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants