@@ -26,7 +26,7 @@ const (
2626 // cache ttl
2727 cacheTTL = 24 * time .Hour
2828 // moderation cache prefix
29- moderationCachePrefix = "moderation:"
29+ moderationCachePrpmptPrefix = "moderation:prompt :"
3030)
3131
3232type Moderation interface {
@@ -94,7 +94,7 @@ func splitContentIntoChunksByWindow(content string) []string {
9494func (modImpl * moderationImpl ) checkSingleChunk (ctx context.Context , content , key string ) (* rpc.CheckResult , error ) {
9595 if modImpl .cacheClient != nil {
9696 chunkHash := md5 .Sum ([]byte (content ))
97- cacheKey := moderationCachePrefix + fmt .Sprintf ("%x" , chunkHash )
97+ cacheKey := moderationCachePrpmptPrefix + fmt .Sprintf ("%x" , chunkHash )
9898 cached , err := modImpl .cacheClient .Get (ctx , cacheKey )
9999 if err == nil {
100100 var result rpc.CheckResult
@@ -112,7 +112,7 @@ func (modImpl *moderationImpl) checkSingleChunk(ctx context.Context, content, ke
112112
113113 if modImpl .cacheClient != nil {
114114 // Cache the result for the single chunk
115- cacheKey := moderationCachePrefix + content
115+ cacheKey := moderationCachePrpmptPrefix + content
116116 resultBytes , err := json .Marshal (result )
117117 if err == nil {
118118 err := modImpl .cacheClient .SetEx (ctx , cacheKey , string (resultBytes ), cacheTTL )
@@ -143,7 +143,7 @@ func (modImpl *moderationImpl) checkBuffer(
143143 // cache each chunk in the current buffer
144144 for _ , chunk := range currentBufferChunks {
145145 chunkHash := md5 .Sum ([]byte (chunk ))
146- cacheKey := moderationCachePrefix + fmt .Sprintf ("%x" , chunkHash )
146+ cacheKey := moderationCachePrpmptPrefix + fmt .Sprintf ("%x" , chunkHash )
147147 resultBytes , err := json .Marshal (result )
148148 if err == nil {
149149 err := modImpl .cacheClient .SetEx (ctx , cacheKey , string (resultBytes ), cacheTTL )
@@ -236,7 +236,7 @@ func (modImpl *moderationImpl) checkLLMPrompt(ctx context.Context, content, key
236236 // Check if chunk is in cache
237237 if modImpl .cacheClient != nil {
238238 chunkHash := md5 .Sum ([]byte (chunk ))
239- cacheKey := moderationCachePrefix + fmt .Sprintf ("%x" , chunkHash )
239+ cacheKey := moderationCachePrpmptPrefix + fmt .Sprintf ("%x" , chunkHash )
240240 cached , err := modImpl .cacheClient .Get (ctx , cacheKey )
241241 if err == nil {
242242 var result rpc.CheckResult
@@ -265,7 +265,7 @@ func (modImpl *moderationImpl) checkLLMPrompt(ctx context.Context, content, key
265265 for _ , chunk := range unCheckedChunks {
266266 if modImpl .cacheClient != nil {
267267 chunkHash := md5 .Sum ([]byte (chunk ))
268- cacheKey := moderationCachePrefix + fmt .Sprintf ("%x" , chunkHash )
268+ cacheKey := moderationCachePrpmptPrefix + fmt .Sprintf ("%x" , chunkHash )
269269 cached , err := modImpl .cacheClient .Get (ctx , cacheKey )
270270 if err == nil {
271271 var result rpc.CheckResult
0 commit comments