polserver/pol-core/bscript/compiler/file/SourceFileCache.h
Eric Swanson 50e42719b8
Add file/SourceFileCache (#222)
* Add file/SourceFileCache

Co-authored-by: Fernando Rozenblit <rozenblit@gmail.com>
2020-08-16 17:22:16 -07:00

38 lines
764 B
C++

#ifndef POLSERVER_SOURCEFILECACHE_H
#define POLSERVER_SOURCEFILECACHE_H
#include <map>
#include <memory>
#include <mutex>
#include <string>
namespace Pol::Bscript::Compiler
{
class SourceFile;
class SourceFileIdentifier;
class Profile;
class Report;
class SourceFileCache
{
public:
explicit SourceFileCache( Profile& profile ) : keep( 0 ), profile( profile ) {}
void configure( unsigned keep );
std::shared_ptr<SourceFile> load( const SourceFileIdentifier&, Report& report );
void keep_some();
private:
unsigned keep;
std::mutex mutex;
std::map<std::string, std::shared_ptr<SourceFile>> files;
std::map<std::string, unsigned> frequency;
Profile& profile;
};
} // namespace Pol::Bscript::Compiler
#endif // POLSERVER_SOURCEFILECACHE_H