Пример #1
0
// test scribble cache getRecord
func TestScribbleGetRecord(t *testing.T) {
	scribbleReset()
	cache.AddRecord(&nanopack)
	_, err := cache.GetRecord("nanobox.io")
	_, err2 := cache.GetRecord("nanopack.io")
	if err == nil || err2 != nil {
		t.Errorf("Failed to get record from scribble cacher - %v%v", err, err2)
	}
}
Пример #2
0
// test nil cache getRecord
func TestNoneGetRecord(t *testing.T) {
	noneReset()
	_, err := cache.GetRecord("nanopack.io")
	if err != nil {
		t.Errorf("Failed to get record from none cacher - %v", err)
	}
}
Пример #3
0
// GetRecord returns a resource for the specified domain
func GetRecord(domain string) (sham.Resource, error) {
	sham.SanitizeDomain(&domain)

	resource, ok := Answers[domain]
	// if domain not cached in memory...
	if !ok {
		// fetch from cache
		record, err := cache.GetRecord(domain)
		if record == nil {
			return resource, fmt.Errorf("Failed to find domain - %v", err)
		}
		// update local cache
		config.Log.Debug("Cache differs from local, updating...")
		Answers[domain] = *record
	}

	return Answers[domain], nil
}