Exemplo n.º 1
0
func findTriggerForApplicationIdAndEvent(application_id_bson bson.ObjectId, event string) Trigger {
	application_id := application_id_bson.Hex()

	key := application_id + ".triggers." + event
	result := Trigger{}

	cache_result, err := cache.Get(key)

	if err {
		query := bson.M{"event": event, "type": "trigger"}

		collection := application_id
		collection += "_triggers"

		database.FindBy(collection, &result, query)

		b, _ := json.Marshal(result)
		cache.Set(key, string(b), 5*time.Minute)
	} else if cache_result.CachedItem == nil {
		json.Unmarshal([]byte(cache_result.Value.(string)), &result)
		cache_result.CachedItem = result
	} else {
		result = cache_result.CachedItem.(Trigger)
	}
	return result
}
Exemplo n.º 2
0
func (application Application) FindEndpointByName(name string) Endpoint {
	result := Endpoint{}

	key := application.Id.Hex() + ".endpoints." + name
	cache_result, err := cache.Get(key)

	if err {
		query := bson.M{"name": name}
		database.FindBy(application.Id.Hex()+"_endpoints", &result, query)

		b, _ := json.Marshal(result)
		cache.Set(key, string(b), 5*time.Minute)

		// Set a second cache item for the endpoint id (This stores reference map data)
		key_id := application.Id.Hex() + ".endpoints." + result.Id.Hex()
		cache.Set(key_id, string(b), 5*time.Minute)
	} else if cache_result.CachedItem == nil {
		json.Unmarshal([]byte(cache_result.Value.(string)), &result)
		cache_result.CachedItem = result
	} else {
		result = cache_result.CachedItem.(Endpoint)
	}

	return result
}
Exemplo n.º 3
0
func (r Record) GetEndpointFromCache() Endpoint {
	endpoint_id := r.EndpointId

	key := r.ApplicationId.Hex() + ".endpoints." + endpoint_id.Hex()
	cache_result, err := cache.Get(key)

	result := Endpoint{}

	if !err {
		if cache_result.CachedItem == nil {
			json.Unmarshal([]byte(cache_result.Value.(string)), &result)
			cache_result.CachedItem = result
		} else {
			result = cache_result.CachedItem.(Endpoint)
		}
	}

	return result
}
Exemplo n.º 4
0
func FindApplicationById(id bson.ObjectId) Application {
	result := Application{}

	key := id.Hex()
	cache_result, err := cache.Get(key)

	if err {
		database.Find(result.Collection(), &result, id)
		b, _ := json.Marshal(result)
		cache.Set(key, string(b), 60*time.Minute)
	} else if cache_result.CachedItem == nil {
		json.Unmarshal([]byte(cache_result.Value.(string)), &result)
		cache_result.CachedItem = result
	} else {
		result = cache_result.CachedItem.(Application)
	}

	return result
}
Exemplo n.º 5
0
func (application Application) FindSessionById(id bson.ObjectId) (Session, bool) {
	result := Session{}

	key := application.Id.Hex() + ".sessions." + id.Hex()
	cache_result, err := cache.Get(key)

	if err {
		query := bson.M{"_id": bson.ObjectId(id)}
		database.FindBy(application.Id.Hex()+"_sessions", &result, query)

		b, _ := json.Marshal(result)
		cache.Set(key, string(b), 5*time.Minute)
	} else if cache_result.CachedItem == nil {
		json.Unmarshal([]byte(cache_result.Value.(string)), &result)
		cache_result.CachedItem = result
	} else {
		result = cache_result.CachedItem.(Session)
	}

	return result, result.Id == bson.ObjectId("")
}