async function skillIndex(language) {
	
	try {
    	
        let expiredDate = new Date();
	        expiredDate.setHours(expiredDate.getHours() - eventCooldown);
		
		/** Get units from cache */
		let skills = await cache.get('swapi', 'skills', {language:language, updated:{ $gte:expiredDate.getTime() }});

		/** Check if existance and expiration */
		if( !skills || !skills[0] ) { 
		
			/** If not found or expired, fetch new from API and save to cache */
			skills = {
			    skills:await swgoh.fetchData({
                    "collection": "skillList",
                    "language": "eng_us",
                    "enums":true,
                    "project": {
                        "id":1, 
                        "abilityReference":1,
                        "isZeta":1
                    }
                }),
                abilities:await swgoh.fetchData({
                    "collection": "abilityList",
                    "language": "eng_us",
                    "enums":true,
                    "project": {
                        "id":1, 
                        "type":1, 
                        "nameKey":1,
                        "descKey":1,
                        "tierList":1
                    }
                }),
                language:language,
			    updated:(new Date()).getTime()
			}
			
			if( !skills.skills && !skills.abilities  ) { throw new Error('Error fetching skills'); } 
			
			skills = await cache.put('swapi', 'skills', {language:language}, skills);

		} else {		
		    skills = skills[0];
		}

		return skills;
		
	} catch(e) { 
		throw e; 
	}    		

}
/**
 *  Fetch localized skills index from cache, or sync if necessary
 * 
 */
Fetch localized skills index from cache, or sync if necessary
Fetch localized skills index from cache or sync if necessary
async function skillIndex(language) {
	try {
        let expiredDate = new Date();
	        expiredDate.setHours(expiredDate.getHours() - eventCooldown);
		let skills = await cache.get('swapi', 'skills', {language:language, updated:{ $gte:expiredDate.getTime() }});
		if( !skills || !skills[0] ) { 
			skills = {
			    skills:await swgoh.fetchData({
                    "collection": "skillList",
                    "language": "eng_us",
                    "enums":true,
                    "project": {
                        "id":1, 
                        "abilityReference":1,
                        "isZeta":1
                    }
                }),
                abilities:await swgoh.fetchData({
                    "collection": "abilityList",
                    "language": "eng_us",
                    "enums":true,
                    "project": {
                        "id":1, 
                        "type":1, 
                        "nameKey":1,
                        "descKey":1,
                        "tierList":1
                    }
                }),
                language:language,
			    updated:(new Date()).getTime()
			}
			if( !skills.skills && !skills.abilities  ) { throw new Error('Error fetching skills'); } 
			skills = await cache.put('swapi', 'skills', {language:language}, skills);
		} else {		
		    skills = skills[0];
		}
		return skills;
	} catch(e) { 
		throw e; 
	}    		
}
async function skillIndex ( language ) { try { let expiredDate = new Date ( ) ; expiredDate . setHours ( expiredDate . getHours ( ) - eventCooldown ) ; let skills = await cache . get ( 'swapi' , 'skills' , { language : language , updated : { $gte : expiredDate . getTime ( ) } } ) ; if ( ! skills || ! skills [ 0 ] ) { skills = { skills : await swgoh . fetchData ( { "collection" : "skillList" , "language" : "eng_us" , "enums" : true , "project" : { "id" : 1 , "abilityReference" : 1 , "isZeta" : 1 } } ) , abilities : await swgoh . fetchData ( { "collection" : "abilityList" , "language" : "eng_us" , "enums" : true , "project" : { "id" : 1 , "type" : 1 , "nameKey" : 1 , "descKey" : 1 , "tierList" : 1 } } ) , language : language , updated : ( new Date ( ) ) . getTime ( ) } if ( ! skills . skills && ! skills . abilities ) { throw new Error ( 'Error fetching skills' ) ; } skills = await cache . put ( 'swapi' , 'skills' , { language : language } , skills ) ; } else { skills = skills [ 0 ] ; } return skills ; } catch ( e ) { throw e ; } }
Fetch localized skills index from cache, or sync if necessary
Fetch localized skills index from cache or sync if necessary
/** Get units from cache */ /** Check if existance and expiration */ /** If not found or expired, fetch new from API and save to cache */