<commit_before>package cadastre

import "fmt"
import "log"
import "os"
import "io"
import "strings"
import "sync/atomic"
import "time"
import "bytes"
import "path/filepath"
import "html/template"
import "encoding/base64"
import "encoding/json"
import "compress/gzip"
import "net/http"
import "github.com/tobz/fsnotify"
import "github.com/tobz/go-cache"
import "github.com/gorilla/mux"

type WebUI struct {
	Configuration *Configuration

	server *http.Server

	templateCache   *cache.Cache
	templateWatcher *fsnotify.Watcher

	RequestsServed uint64
	RequestErrors  uint64
	CacheRequests  uint64
	CacheHits      uint64
}

func (me *WebUI) StartListening() error {
	var err error

	// Initiailize our statistics.
	me.RequestsServed = 0
	me.RequestErrors = 0
	me.CacheRequests = 0
	me.CacheHits = 0

	log.Printf("Instantiating template cache...")

	// Set up our template cache and template watcher.
	me.templateCache = cache.New((time.Minute * 30), (time.Second * 30))
	me.templateWatcher, err = fsnotify.NewWatcher()
	if err != nil {
		return fmt.Errorf("Unable to instantiate template watcher! %s", err)
	}

	go func() {
		for {
			select {
			// Something happened in our template directory.  Invalidate the cache.
			case ev := <-me.templateWatcher.Event:
				log.Printf("Detected change to template file '%s'.  Flushing template cache.", ev.Name)
				me.templateCache.Flush()
			}
		}
	}()

	absTemplateDirectory, err := filepath.Abs(me.Configuration.TemplateDirectory)
	if err != nil {
		return fmt.Errorf("Caught an error trying to get the absolute path to the template directory! %s", err)
	}

	// Watch our template directory for changes so that we invalidate the cache  Only watch for modifications and deletes.
	me.templateWatcher.WatchFlags(absTemplateDirectory, fsnotify.FSN_MODIFY)

	log.Printf("Creating HTTP server...")

	// Set up our request multiplexer.
	requestMultiplexer := mux.NewRouter()

	// Create our server instance using our request multiplexer.
	me.server = &http.Server{
		Addr:    me.Configuration.ListenAddress,
		Handler: requestMultiplexer,
	}<commit_msg>Switched to my own key/value cache and back to howeyc for fsnotify.<commit_after>package cadastre

import "fmt"
import "log"
import "os"
import "io"
import "strings"
import "sync/atomic"
import "time"
import "bytes"
import "path/filepath"
import "html/template"
import "encoding/base64"
import "encoding/json"
import "compress/gzip"
import "net/http"
import "github.com/howeyc/fsnotify"
import "github.com/tobz/gocache"
import "github.com/gorilla/mux"

type WebUI struct {
	Configuration *Configuration

	server *http.Server

	templateCache   *gocache.Cache
	templateWatcher *fsnotify.Watcher

	RequestsServed uint64
	RequestErrors  uint64
	CacheRequests  uint64
	CacheHits      uint64
}

func (me *WebUI) StartListening() error {
	var err error

	// Initiailize our statistics.
	me.RequestsServed = 0
	me.RequestErrors = 0
	me.CacheRequests = 0
	me.CacheHits = 0

	log.Printf("Instantiating template cache...")

	// Set up our template cache and template watcher.
	me.templateCache = gocache.New((time.Minute * 30), (time.Second * 30))
	me.templateWatcher, err = fsnotify.NewWatcher()
	if err != nil {
		return fmt.Errorf("Unable to instantiate template watcher! %s", err)
	}

	go func() {
		for {
			select {
			// Something happened in our template directory.  Invalidate the cache.
			case ev := <-me.templateWatcher.Event:
				log.Printf("Detected change to template file '%s'.  Flushing template cache.", ev.Name)
				me.templateCache.Clear()
			}
		}
	}()

	absTemplateDirectory, err := filepath.Abs(me.Configuration.TemplateDirectory)
	if err != nil {
		return fmt.Errorf("Caught an error trying to get the absolute path to the template directory! %s", err)
	}

	// Watch our template directory for changes so that we invalidate the cache  Only watch for modifications and deletes.
	me.templateWatcher.WatchFlags(absTemplateDirectory, fsnotify.FSN_MODIFY)

	log.Printf("Creating HTTP server...")

	// Set up our request multiplexer.
	requestMultiplexer := mux.NewRouter()

	// Create our server instance using our request multiplexer.
	me.server = &http.Server{
		Addr:    me.Configuration.ListenAddress,
		Handler: requestMultiplexer,
	}
{'fraction_non_alphanumeric': 0.1041814316087881, 'fraction_numerical': 0.008504606661941885, 'mean_word_length': 4.157125456760049, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1380988', 'n_tokens_mistral': 1429, 'n_tokens_neox': 1333, 'n_words': 405}