/* osgEarth
 * Copyright 2025 Pelican Mapping
 * MIT License
 */
#ifndef OSGEARTH_MEMCACHE_H
#define OSGEARTH_MEMCACHE_H 1

#include <osgEarth/Cache>

namespace osgEarth
{
    /**
     * An in-memory cache.
     * Each bin in this cache has its own locking mechanism for thread-safety. Each
     * bin also maintains an LRU list for maintaining the size cap.
     */
    class OSGEARTH_EXPORT MemCache : public Cache
    {
    public:
        MemCache( unsigned maxBinSize =16 );
        META_Object( osgEarth, MemCache );

        /** dtor */
        virtual ~MemCache() { }

        void dumpStats(const std::string& binID);

    public: // Cache interface

        virtual CacheBin* addBin(const std::string& binID);

        virtual CacheBin* getOrCreateBin(const std::string& binID);

        virtual CacheBin* getOrCreateDefaultBin();
    
    private:
        MemCache( const MemCache& rhs, const osg::CopyOp& op =osg::CopyOp::DEEP_COPY_ALL ) 
         : Cache( rhs, op ) 
         , _maxBinSize(rhs._maxBinSize)
        { }

        unsigned _maxBinSize;
    };

} // namespace osgEarth

#endif // OSGEARTH_MEMCACHE_H
