// Copyright (C) 2023 CGI France
//
// This file is part of TIPO.
//
// TIPO is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// TIPO is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with TIPO.  If not, see <http://www.gnu.org/licenses/>.

package swap

type CacheList struct {
	caches []*Cache
}

// NewCacheList creates a new empty cache list.
func NewCacheList() *CacheList {
	return &CacheList{caches: []*Cache{}}
}

// Add a cache to the cache list.
func (cl *CacheList) Add(cache *Cache) {
	cl.caches = append(cl.caches, cache)
}

// All returns all caches in the cache list.
func (cl *CacheList) All() []*Cache {
	return cl.caches
}

// Post the row to feed all caches with new tuples.
func (cl *CacheList) Post(row Row) {
	for _, cache := range cl.caches {
		cache.Post(row)
	}
}
