organ-ai-zer
Version:
AI-powered file organizer CLI tool
55 lines • 1.87 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProjectDetectionCache = void 0;
const base_cache_1 = require("./base-cache");
/**
* Project Detection Cache Service
* Caches expensive project detection operations to improve performance
*/
class ProjectDetectionCache extends base_cache_1.BaseCache {
constructor() {
super({
subDirectory: 'projects',
ttlMs: 10 * 60 * 1000, // 10 minutes (aligned with documentation TTL)
filePrefix: 'projects_'
});
}
static getInstance() {
if (!ProjectDetectionCache.instance) {
ProjectDetectionCache.instance = new ProjectDetectionCache();
}
return ProjectDetectionCache.instance;
}
/**
* Get cached project detection results
*/
async getCachedProjects(directory, files) {
const cachedData = await this.getCached(directory, files);
return cachedData ? cachedData.projects : null;
}
/**
* Cache project detection results
*/
async cacheProjects(directory, files, projects) {
const scanDepth = this.calculateScanDepth(files, directory);
const projectData = {
projects,
scanDepth
};
return this.cache(directory, files, projectData);
}
/**
* Calculate scan depth for a set of files relative to base directory
*/
calculateScanDepth(files, baseDirectory) {
if (files.length === 0)
return 0;
const maxDepth = Math.max(...files.map(file => {
const relativePath = file.path.replace(baseDirectory, '').replace(/^[\/\\]/, '');
return relativePath.split(/[\/\\]/).length;
}));
return maxDepth;
}
}
exports.ProjectDetectionCache = ProjectDetectionCache;
//# sourceMappingURL=project-detection-cache.js.map