<commit_before>import { Inject, Injectable } from '@angular/core';
import { IImageryConfig } from '@ansyn/imagery/model/iimagery-config';
import { ConfigurationToken } from '@ansyn/imagery/model/configuration.token';
import { ImageryCommunicatorService } from '@ansyn/imagery';

@Injectable()
export class CacheService {

	protected cacheSize = this.config.maxCachedLayers || 100;
	protected cachedLayesrMap: Map<string, any> = new Map<string, any>();

	constructor(@Inject(ConfigurationToken) protected config: IImageryConfig,
				public imageryCommunicatorService: ImageryCommunicatorService) {
	}

	isDisplayedLayer(layers) {
		return this.imageryCommunicatorService
			.communicatorsAsArray()
			.some((communicator) => {
				const communicatorLayers = communicator.getLayers();
				return layers.some((layer) => communicatorLayers.includes(layer));
			})
	}

	getLayerFromCache(overlay: any): any[] {
		const layers = this.cachedLayesrMap.get(this.createLayerId(overlay));
		return layers && !this.isDisplayedLayer(layers) ? [ ...layers ] : [];
	}

	addLayerToCache(overlay: any, layers: any[]) {
		if (this.cachedLayesrMap.size >= this.cacheSize) {
			const key = this.cachedLayesrMap.keys().next();
			this.cachedLayesrMap.delete(key.value);
		}
		this.cachedLayesrMap.set(this.createLayerId(overlay), [...layers]);
	}

	removeLayerFromCache(overlay: any) {
		this.cachedLayesrMap.delete(this.createLayerId(overlay));
	}

	createLayerId(overlay: any): string {
		return `${overlay.sourceType}/${JSON.stringify(overlay)}`;
	}
}<commit_msg>fix(cache-service): add cacheId to ol layer<commit_after>import { Inject, Injectable } from '@angular/core';
import { IImageryConfig } from '@ansyn/imagery/model/iimagery-config';
import { ConfigurationToken } from '@ansyn/imagery/model/configuration.token';
import { ImageryCommunicatorService } from '@ansyn/imagery';

@Injectable()
export class CacheService {

	protected cacheSize = this.config.maxCachedLayers || 100;
	protected cachedLayesrMap: Map<string, any> = new Map<string, any>();

	constructor(@Inject(ConfigurationToken) protected config: IImageryConfig,
				public imageryCommunicatorService: ImageryCommunicatorService) {
	}

	isDisplayedLayer(layers, cacheId) {
		return this.imageryCommunicatorService
			.communicatorsAsArray()
			.some((communicator) => {
				const communicatorLayers = communicator.getLayers();
				return layers.some((layer) => communicatorLayers.some((layer) => layer.get('cacheId') === cacheId));
			})
	}

	getLayerFromCache(overlay: any): any[] {
		const cacheId = this.createLayerId(overlay);
		const layers = this.cachedLayesrMap.get(cacheId);
		return layers && !this.isDisplayedLayer(layers, cacheId) ? [ ...layers ] : [];
	}

	addLayerToCache(overlay: any, layers: any[]) {
		if (this.cachedLayesrMap.size >= this.cacheSize) {
			const key = this.cachedLayesrMap.keys().next();
			this.cachedLayesrMap.delete(key.value);
		}
		const cacheId = this.createLayerId(overlay);
		layers.forEach((layer) => layer.set('cacheId', cacheId));
		this.cachedLayesrMap.set(cacheId, [...layers]);
	}

	removeLayerFromCache(overlay: any) {
		this.cachedLayesrMap.delete(this.createLayerId(overlay));
	}

	createLayerId(overlay: any): string {
		return `${overlay.sourceType}/${JSON.stringify(overlay)}`;
	}
}
{'fraction_non_alphanumeric': 0.14242239805234327, 'fraction_numerical': 0.0018259281801582471, 'mean_word_length': 5.600401606425703, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7655498', 'n_tokens_mistral': 1148, 'n_tokens_neox': 1057, 'n_words': 180}