I've implemented a kind of "memcache without the d" which takes care
of expiring items you put in the cache -- you can find it here:
https://github.com/pmylund/go-cache. It would probably be overkill for
a single page, but if you're caching many different types of things,
and don't want to set up a distributed cache/many different variables
to keep track of each item, it may be interesting.
I was actually looking for some kind of memcache without the d. I will
have a look into this. Thank you a lot :)
>
> On Wed, Apr 18, 2012 at 08:54, Sankar <sankar.c...@gmail.com> wrote:
>> Hi,
>>
>> I have a static webpage in my webapp, which will be accessed by many
>> people frequently. Is there a built-in or best way to cache this
>> static page in the go http server, instead of asking it to go to the
>> disk everytime ? My app. is not deployed in the appengine btw.
>>
>> Thanks.
>>
>> Sankar
>> http://psankar.blogspot.com
--
Sankar P
http://psankar.blogspot.com
If your site is hit very frequently. Avoiding to hit the app entirely
is probably preferable. Then using something like Varnish[1] can be a
good solution. If you don't mind the HTTP request reaching your
application, using Brad's memcache client[2] together with a memcache
server is also good.
[1]: http://varnish-cache.org
[2]: https://github.com/bradfitz/gomemcache/
shove all your static pages into a map[string]bytes.Buffer :)
zero cache eviction, but it should work for a set size of 1 page.
Yes, I was planning to implement a FileCache myself, but wanted to
find out if there are any other options provided by golang already,
which I can just consume. Thanks.
This is not for a production app. It is just a fun project which I am
doing to learn something, and hoping that it will be useful for
someone too. I will try to use memcached and will fallback to loading
from a custom filecache implementation if memcached is not running.
Thanks a lot.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
Benchmark on mac: darwin 64 ~/gocode/src/github.com/ranveerkunal/memfs % go test memfs_test.go -bench=. -cpu=4 -parallel=4 temp dir: /tmp/memfs731592791 writing big file ready to benchmark ... testing: warning: no tests to run PASS BenchmarkNonExistentMemFS-4 500000 2779 ns/op BenchmarkNonExistentDiskFS-4 200000 7513 ns/op BenchmarkBigFileMemFS-4 20 88782691 ns/op BenchmarkBigFileDiskFS-4 20 86461808 ns/op ok command-line-arguments 20.301s
Benchmark on mac: darwin 64 ~/gocode/src/github.com/ranveerkunal/memfs
% go test memfs_test.go -bench=. -cpu=4 -parallel=4 temp dir: /tmp/memfs406771321 writing small file writing big file ready to benchmark ... testing: warning: no tests to run PASS BenchmarkNonExistentMemFS-4 5000000 700 ns/op BenchmarkNonExistentDiskFS-4 500000 3996 ns/op BenchmarkSmallFileMemFS-4 10000 111634 ns/op BenchmarkSmallFileDiskFS-4 10000 128475 ns/op BenchmarkBigFileMemFS-4 20 83455262 ns/op BenchmarkBigFileDiskFS-4 20 96320175 ns/op ok command-line-arguments 26.610s
Benchmark on linux: ~/gocode/src/github.com/ranveerkunal/memfs % go test memfs_test.go -bench=. -cpu=4 -parallel=4 temp dir: /tmp/memfs945391658 writing small file writing big file ready to benchmark ... testing: warning: no tests to run PASS BenchmarkNonExistentMemFS-4 500000 7918 ns/op BenchmarkNonExistentDiskFS-4 100000 16862 ns/op BenchmarkSmallFileMemFS-4 2000 811382 ns/op BenchmarkSmallFileDiskFS-4 2000 836498 ns/op BenchmarkBigFileMemFS-4 5 4629695200 ns/op BenchmarkBigFileDiskFS-4 1 11134569000 ns/op ok command-line-arguments 109.350s