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

		/** Check if existance and expiration */
		if( !events || !events[0] ) { 
		
			/** If not found or expired, fetch new from API and save to cache */
			events = {
			    events:await swgoh.fetchEvents({ language:language }),
			    updated:(new Date()).getTime()
			}
			
			if( !events.events ) { throw new Error('Error fetching events'); } 
			
			events = await cache.put('swapi', 'events', {}, events);

		} else {		
		    events = events[0];
		}

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

}
/**
 *  Fetch swgoh event schedule from cache, and sync if necessary
 * 
 */
Fetch swgoh event schedule from cache, and sync if necessary
Fetch swgoh event schedule from cache and sync if necessary
async function events(language) {
	try {
        let expiredDate = new Date();
	        expiredDate.setHours(expiredDate.getHours() - eventCooldown);
		let events = await cache.get('swapi', 'events', {updated:{ $gte:expiredDate.getTime() }});
		if( !events || !events[0] ) { 
			events = {
			    events:await swgoh.fetchEvents({ language:language }),
			    updated:(new Date()).getTime()
			}
			if( !events.events ) { throw new Error('Error fetching events'); } 
			events = await cache.put('swapi', 'events', {}, events);
		} else {		
		    events = events[0];
		}
		return events;
	} catch(e) { 
		throw e; 
	}    		
}
async function events ( language ) { try { let expiredDate = new Date ( ) ; expiredDate . setHours ( expiredDate . getHours ( ) - eventCooldown ) ; let events = await cache . get ( 'swapi' , 'events' , { updated : { $gte : expiredDate . getTime ( ) } } ) ; if ( ! events || ! events [ 0 ] ) { events = { events : await swgoh . fetchEvents ( { language : language } ) , updated : ( new Date ( ) ) . getTime ( ) } if ( ! events . events ) { throw new Error ( 'Error fetching events' ) ; } events = await cache . put ( 'swapi' , 'events' , { } , events ) ; } else { events = events [ 0 ] ; } return events ; } catch ( e ) { throw e ; } }
Fetch swgoh event schedule from cache, and sync if necessary
Fetch swgoh event schedule from cache and sync if necessary
/** Get player from cache */ /** Check if existance and expiration */ /** If not found or expired, fetch new from API and save to cache */