You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: cast_auth.go
    path of file: ./repos/ente/server/pkg/middleware
    
    the code of the file until where you have to start completion: package middleware

import (
	"fmt"
	castCtrl "github.com/ente-io/museum/pkg/controller/cast"
	"github.com/ente-io/museum/pkg/utils/auth"
	"github.com/gin-gonic/gin"
	"github.com/patrickmn/go-cache"
	"net/http"
)

// CastMiddleware intercepts and authenticates incoming requests
type CastMiddleware struct {
	Cache    *cache.Cache
	CastC
    
func (m *CastMiddleware) CastAuthMiddleware() gin.HandlerFunc {
	return func(c *gin.Context) {
		token := auth.GetCastToken(c)
		if token == "" {
			c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "cast access token missing"})
			return
		}
		app := auth.GetApp(c)
		cacheKey := fmt.Sprintf("%s:%s:%s", app, token, "cast")
		cachedCastCtx, found := m.Cache.Get(cacheKey)
		if !found {
			castCtx, err := m.CastCtrl.GetCollectionAndCasterIDForToken(c, token)
			if err != nil {
				c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "invalid token"})
				return
			}
			c.Set(auth.CastContext, castCtx)
			m.Cache.Set(cacheKey, *castCtx, cache.DefaultExpiration)
			c.Set(auth.CastContext, *castCtx)
		} else {
			c.Set(auth.CastContext, cachedCastCtx)
			// validate async validate that the token is still active
			go func() {
				_, err := m.CastCtrl.GetCollectionAndCasterIDForToken(c, token)
				if err != nil {
					m.Cache.Delete(cacheKey)
				}
			}()
		}
		c.Next()
	}
}