@@ -46,19 +46,31 @@ func (s *ExecutionCacheStore) GetExecutionCache(executionCacheKey string, cacheS
4646 if cacheStaleness == 0 {
4747 return nil , fmt .Errorf ("CacheStaleness=0, Cache is disabled." )
4848 }
49- r , err := s .db .Table ("execution_caches" ).Where ("ExecutionCacheKey = ?" , executionCacheKey ).Rows ()
50- if err != nil {
51- return nil , fmt .Errorf ("Failed to get execution cache: %q, err: %v" , executionCacheKey , err )
49+ // Use GORM's standard query method with struct field name to avoid case-sensitivity issues
50+ var executionCaches []model.ExecutionCache
51+ result := s .db .Where (& model.ExecutionCache {ExecutionCacheKey : executionCacheKey }).Find (& executionCaches )
52+ if result .Error != nil {
53+ return nil , fmt .Errorf ("failed to get execution cache: %q, err: %v" , executionCacheKey , result .Error )
5254 }
53- defer r .Close ()
54- executionCaches , err := s .scanRows (r , cacheStaleness )
55- if err != nil {
56- return nil , fmt .Errorf ("Failed to scan rows on execution cache: %q, err: %v" , executionCacheKey , err )
55+
56+ // Filter by cache staleness
57+ var validCaches []* model.ExecutionCache
58+ for i := range executionCaches {
59+ cache := & executionCaches [i ]
60+ log .Println ("Get id: " + strconv .FormatInt (cache .ID , 10 ))
61+ log .Println ("Get template: " + cache .ExecutionTemplate )
62+ // maxCacheStaleness comes from the database entry.
63+ // cacheStaleness is computed from the pods annotation and environment variables.
64+ if (cache .MaxCacheStaleness < 0 || s .time .Now ().UTC ().Unix ()- cache .StartedAtInSec <= cache .MaxCacheStaleness ) &&
65+ (cacheStaleness < 0 || s .time .Now ().UTC ().Unix ()- cache .StartedAtInSec <= cacheStaleness ) {
66+ validCaches = append (validCaches , cache )
67+ }
5768 }
58- if len (executionCaches ) == 0 {
69+
70+ if len (validCaches ) == 0 {
5971 return nil , fmt .Errorf ("Execution cache not found with cache key: %q" , executionCacheKey )
6072 }
61- latestCache , err := getLatestCacheEntry (executionCaches )
73+ latestCache , err := getLatestCacheEntry (validCaches )
6274 if err != nil {
6375 return nil , err
6476 }
@@ -140,17 +152,15 @@ func getLatestCacheEntry(executionCaches []*model.ExecutionCache) (*model.Execut
140152func (s * ExecutionCacheStore ) CreateExecutionCache (executionCache * model.ExecutionCache ) (* model.ExecutionCache , error ) {
141153 log .Printf ("checking for existing row with cache key: %s before insertion" , executionCache .ExecutionCacheKey )
142154
143- r , err := s .db .Table ("execution_caches" ).Where ("ExecutionCacheKey = ?" , executionCache .ExecutionCacheKey ).Rows ()
144- if err != nil {
145- log .Printf ("Failed to get execution cache with key: %s, err: %v" , executionCache .ExecutionCacheKey , err )
146- return nil , err
155+ // Use GORM's standard query method with struct field name to avoid case-sensitivity issues
156+ var existingCaches []model.ExecutionCache
157+ result := s .db .Where (& model.ExecutionCache {ExecutionCacheKey : executionCache .ExecutionCacheKey }).Find (& existingCaches )
158+ if result .Error != nil {
159+ log .Printf ("Failed to get execution cache with key: %s, err: %v" , executionCache .ExecutionCacheKey , result .Error )
160+ return nil , result .Error
147161 }
148162
149- rowCount := 0
150-
151- for r .Next () {
152- rowCount ++
153- }
163+ rowCount := len (existingCaches )
154164 log .Printf ("number of rows returned for existing rows check: %d" , rowCount )
155165
156166 if rowCount == 0 {
0 commit comments