<commit_before>package main

import (
    "flag"    
    "io/ioutil"
    "fmt"
    "log"
    "net/http"
    "html"
    "time"
    "strings"    
    "path/filepath"
    "github.com/antonholmquist/jason"
    "github.com/patrickmn/go-cache"    
)


var http_port_string = flag.String("http.port","8080", "HTTP Listen port")
var property_location_string = flag.String("json.location","./data", "Location of json files")

func check(e error) {
    if e != nil {
        panic(e)
    }
}


func main(){
	flag.Parse()

	var port=*http_port_string

	fmt.Printf("HTTP Listen port: %s\n", port)
	fmt.Printf("JSON location: %s\n", *property_location_string)

	// Create a cache with a default expiration time of 5 minutes, and which
    // purges expired items every 30 seconds
    propertyCache := cache.New(5*time.Minute, 30*time.Second)

    http.HandleFunc("/service/json", func(w http.ResponseWriter, r *http.Request) {
    	files, _ := ioutil.ReadDir(*property_location_string)
	    for _, f := range files {
	    	filename:=f.Name()
	    	extension:= filepath.Ext(filename)
			var name = filename[0:len(filename)-len(extension)]
	    	fmt.Fprintf(w, "%s\n",name)	            
	    }
    })

    http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
    	fmt.Fprintf(w, "OK")
    })

	http.HandleFunc("/json/", func(w http.ResponseWriter, r *http.Request) {

		fullUrl:=r.URL.Path

		foo, found := propertyCache.Get(fullUrl)
        if found {
            //fmt.Fprintf(w, "Value (cached): %s\n", foo)
            fmt.Fprintf(w, "%s", foo)
            return
        }		<commit_msg>Configure the cache ttl and purge interval in CLI<commit_after>package main

import (
    "flag"    
    "io/ioutil"
    "fmt"
    "log"
    "net/http"
    "html"
    "time"
    "strings"  
    "strconv"  
    "path/filepath"
    "github.com/antonholmquist/jason"
    "github.com/patrickmn/go-cache"    
)


var http_port_string = flag.String("http.port","8080", "HTTP Listen port")
var property_location_string = flag.String("json.location","./data", "Location of json files")

var cache_ttl_string = flag.String("cache.ttl","300", "Property cache TTL in seconds")
var cache_purge_interval_string = flag.String("cache.purge.interval","30", "Property cache purge interval in seconds")

func check(e error) {
    if e != nil {
        panic(e)
    }
}

func getPropertyIntValue(value string) (int64){
	var p,err=strconv.ParseInt(value, 10, 64)
	if err != nil {
		fmt.Printf("Invalid integer value: %s\n", value)
		panic(err)
	}	
	return p
}


func main(){
	flag.Parse()

	var port=*http_port_string

	ttl:=getPropertyIntValue(*cache_ttl_string)
	purge_interval:=getPropertyIntValue(*cache_purge_interval_string)


	fmt.Printf("HTTP Listen port: %s\n", port)
	fmt.Printf("JSON location: %s\n", *property_location_string)

	fmt.Printf("Cache TTL in seconds: %d\n", ttl)
	fmt.Printf("Cache purge interval in seconds: %d\n", purge_interval)

	// Create a cache with a default expiration time of 5 minutes, and which
    // purges expired items every 30 seconds
    propertyCache := cache.New(time.Duration(ttl) * time.Second, time.Duration(purge_interval) * time.Second)

    http.HandleFunc("/service/json", func(w http.ResponseWriter, r *http.Request) {
    	files, _ := ioutil.ReadDir(*property_location_string)
	    for _, f := range files {
	    	filename:=f.Name()
	    	extension:= filepath.Ext(filename)
			var name = filename[0:len(filename)-len(extension)]
	    	fmt.Fprintf(w, "%s\n",name)	            
	    }
    })

    http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
    	fmt.Fprintf(w, "OK")
    })

	http.HandleFunc("/json/", func(w http.ResponseWriter, r *http.Request) {

		fullUrl:=r.URL.Path

		foo, found := propertyCache.Get(fullUrl)
        if found {
            //fmt.Fprintf(w, "Value (cached): %s\n", foo)
            fmt.Fprintf(w, "%s", foo)
            return
        }		
{'fraction_non_alphanumeric': 0.14672110232202093, 'fraction_numerical': 0.007655014034192396, 'mean_word_length': 3.0790842872008324, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6084417', 'n_tokens_mistral': 1415, 'n_tokens_neox': 1334, 'n_words': 294}