// Writes IResponse into connection. func (s *SessionHandler) writeResponse(resp iface.IResponse) error { unsafeData := common.UnsafeStringToBytes(resp.GetResponse()) if _, err := s.conn.Write(unsafeData); err != nil { return err } if _, err := s.conn.Write(EOM); err != nil { return err } return nil }
// FlushCache flushes all cache into database. func (ds *DataStorage) FlushCache() { if ds.closed { return } ds.cacheLock.Lock() tmpItemCache := ds.itemCache ds.tmpPayloadCache = ds.payloadCache ds.itemCache = make(map[string][]byte) ds.payloadCache = make(map[string]string) ds.cacheLock.Unlock() wb := levigo.NewWriteBatch() for k, v := range tmpItemCache { key := common.UnsafeStringToBytes(k) if v == nil { wb.Delete(key) } else { wb.Put(key, v) } } for k, v := range ds.tmpPayloadCache { key := common.UnsafeStringToBytes(k) if v == "" { wb.Delete(key) } else { wb.Put(key, common.UnsafeStringToBytes(v)) } } ds.db.Write(defaultWriteOptions, wb) ds.cacheLock.Lock() ds.tmpPayloadCache = make(map[string]string) ds.cacheLock.Unlock() }
func makeSettingsKey(serviceId string) []byte { return common.UnsafeStringToBytes(serviceConfigPrefix + serviceId) }
// SaveServiceMeta stores service metadata into database. func (ds *DataStorage) SaveServiceMeta(serviceDescription *common.ServiceDescription) { key := serviceDescriptionPrefix + serviceDescription.GetName() data, _ := serviceDescription.Marshal() ds.db.Put(defaultWriteOptions, common.UnsafeStringToBytes(key), data) }
// IterServiceItems returns new over all service item metadata. // Service name used as a prefix to file all service items. func (ds *DataStorage) IterServiceItems(serviceId string) *ItemIterator { iter := ds.db.NewIterator(defaultReadOptions) prefix := common.UnsafeStringToBytes(makeItemID(serviceId, "")) return makeItemIterator(iter, prefix) }