MCPcopy Create free account
hub / github.com/astercloud/aster / Get

Method Get

pkg/knowledge/manager.go:294–325  ·  view source on GitHub ↗

Get 获取知识项

(ctx context.Context, id string)

Source from the content-addressed store, hash-verified

292
293// Get 获取知识项
294func (m *manager) Get(ctx context.Context, id string) (*KnowledgeItem, error) {
295 m.mu.RLock()
296 defer m.mu.RUnlock()
297
298 // 先检查缓存
299 if m.config.CacheEnabled {
300 if entry, exists := m.cache[id]; exists {
301 if time.Now().Before(entry.expire) {
302 return entry.item, nil
303 }
304 delete(m.cache, id)
305 }
306 }
307
308 // 从内存获取
309 item, err := m.getItemFromMemory(ctx, id)
310 if err != nil {
311 return nil, fmt.Errorf("knowledge: failed to get item: %w", err)
312 }
313
314 // 更新缓存
315 if m.config.CacheEnabled {
316 m.updateCache(item)
317 }
318
319 // 记录审计
320 if m.config.EnableAudit {
321 m.audit("get", "", item.ID, "Retrieved knowledge item: "+item.Title)
322 }
323
324 return item, nil
325}
326
327// Update 更新知识项
328func (m *manager) Update(ctx context.Context, item *KnowledgeItem) error {

Callers 3

SearchSimilarMethod · 0.95
ValidateMethod · 0.95
RefreshMethod · 0.95

Calls 4

getItemFromMemoryMethod · 0.95
updateCacheMethod · 0.95
auditMethod · 0.95
deleteFunction · 0.85

Tested by

no test coverage detected