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: cache_with_ttl.go
    path of file: ./repos/parca/pkg/cache
    
    the code of the file until where you have to start completion: // Copyright 2023-2024 The Parca Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance wit
    
func NewLRUCacheWithTTL[K comparable, V any](reg prometheus.Registerer, maxEntries int, ttl time.Duration, opts ...CacheWithTTLOptions) *LRUCacheWithTTL[K, V] {
	lruOpts := []lru.Option[K, valueWithDeadline[V]]{
		lru.WithMaxSize[K, valueWithDeadline[V]](maxEntries),
	}
	c := &LRUCacheWithTTL[K, V]{
		mtx: &sync.RWMutex{},
		ttl: ttl,
	}
	if len(opts) > 0 {
		c.updateDeadlineOnGet = opts[0].UpdateDeadlineOnGet
		c.removeExpiredOnAdd = opts[0].RemoveExpiredOnAdd
		if c.removeExpiredOnAdd {
			c.nextRemoveExpired = time.Now().Add(ttl)
			lruOpts = append(lruOpts, lru.WithOnAdded[K, valueWithDeadline[V]](func(key K, value valueWithDeadline[V]) {
				now := time.Now()
				if c.nextRemoveExpired.Before(now) {
					// Happens in "Add" inside a lock, so we don't need to lock here.
					c.lru.RemoveMatching(func(k K, v valueWithDeadline[V]) bool {
						return v.deadline.Before(now)
					})
					c.nextRemoveExpired = now.Add(ttl)
				}
			}))
		}
	}
	c.lru = lru.New[K, valueWithDeadline[V]](reg, lruOpts...)
	return c
}