from . import base


class RoutesCachePreprocessor(base.BasePreprocessor):
    KIND = '_routes_cache'

    def __init__(self, pod):
        self.pod = pod

    def run(self, build=True):
        self.pod.routes.reset_cache(rebuild=True)

    def list_watched_dirs(self):
        return ['/content/', '/static/']

import datetime
from . import base


class RoutesCachePreprocessor(base.BasePreprocessor):
    KIND = '_routes_cache'
    LIMIT = datetime.timedelta(seconds=1)

    def __init__(self, pod):
        self.pod = pod
        self._last_run = None

    def run(self, build=True):
        # Avoid rebuilding routes cache more than once per second.
        now = datetime.datetime.now()
        limit = RoutesCachePreprocessor.LIMIT
        if not self._last_run or (now - self._last_run) > limit:
            self.pod.routes.reset_cache(rebuild=True, inject=False)
            self._last_run = now

    def list_watched_dirs(self):
        return ['/content/']

Implement ratelimit on routes cache.
Implement ratelimit on routes cache.

+ import datetime
  from . import base
  
  
  class RoutesCachePreprocessor(base.BasePreprocessor):
      KIND = '_routes_cache'
+     LIMIT = datetime.timedelta(seconds=1)
  
      def __init__(self, pod):
          self.pod = pod
+         self._last_run = None
  
      def run(self, build=True):
+         # Avoid rebuilding routes cache more than once per second.
+         now = datetime.datetime.now()
+         limit = RoutesCachePreprocessor.LIMIT
+         if not self._last_run or (now - self._last_run) > limit:
-         self.pod.routes.reset_cache(rebuild=True)
+             self.pod.routes.reset_cache(rebuild=True, inject=False)
+             self._last_run = now
  
      def list_watched_dirs(self):
-         return ['/content/', '/static/']
+         return ['/content/']
  
Implement ratelimit on routes cache.
## Code Before:
from . import base


class RoutesCachePreprocessor(base.BasePreprocessor):
    KIND = '_routes_cache'

    def __init__(self, pod):
        self.pod = pod

    def run(self, build=True):
        self.pod.routes.reset_cache(rebuild=True)

    def list_watched_dirs(self):
        return ['/content/', '/static/']

## Instruction:
Implement ratelimit on routes cache.
## Code After:
import datetime
from . import base


class RoutesCachePreprocessor(base.BasePreprocessor):
    KIND = '_routes_cache'
    LIMIT = datetime.timedelta(seconds=1)

    def __init__(self, pod):
        self.pod = pod
        self._last_run = None

    def run(self, build=True):
        # Avoid rebuilding routes cache more than once per second.
        now = datetime.datetime.now()
        limit = RoutesCachePreprocessor.LIMIT
        if not self._last_run or (now - self._last_run) > limit:
            self.pod.routes.reset_cache(rebuild=True, inject=False)
            self._last_run = now

    def list_watched_dirs(self):
        return ['/content/']
