-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added Redis Cache Driver * Finalized Redis Cache Driver * Merge 2.0 into master (#443) * bumped version * fixed connection credentials * bumped version * fixed amqp driver to pickup connection when lost (#442) * bumped version * updated test * Added ability to add jinja extensions (#458) * started to add ability to use other file extensions * fixed search path and pugjs * fixed pypug dependency * Add custom exception handlers (#459) * added ability to add custom exception handlers * added more * added debug exception * added debug exception to tests * added dd and templates * fixed manifest file * removed print statement
- Loading branch information
1 parent
e2e22ce
commit ae29340
Showing
23 changed files
with
530 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
include masonite/snippets/exceptions/css/* | ||
include masonite/snippets/exceptions/* | ||
include masonite/snippets/* | ||
include masonite/snippets/auth/controllers/* | ||
include masonite/snippets/auth/templates/auth/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from cleo import Command | ||
from masonite.exceptions import DebugException | ||
|
||
class TestController: | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
"""Base cache driver module. | ||
""" | ||
|
||
from masonite.drivers.BaseDriver import BaseDriver | ||
|
||
|
||
class BaseCacheDriver(BaseDriver): | ||
"""Base class that all cache drivers inherit from. | ||
""" | ||
|
||
def calculate_time(self, cache_type, cache_time): | ||
"""Convert time to required unit | ||
Returns: | ||
self | ||
""" | ||
|
||
cache_type = cache_type.lower() | ||
calc = 0 | ||
|
||
if cache_type in ("second", "seconds"): | ||
# Set time now for | ||
calc = 1 | ||
elif cache_type in ("minute", "minutes"): | ||
calc = 60 | ||
elif cache_type in ("hour", "hours"): | ||
calc = 60 * 60 | ||
elif cache_type in ("day", "days"): | ||
calc = 60 * 60 * 60 | ||
elif cache_type in ("month", "months"): | ||
calc = 60 * 60 * 60 * 60 | ||
elif cache_type in ("year", "years"): | ||
calc = 60 * 60 * 60 * 60 * 60 | ||
else: | ||
raise ValueError( | ||
'{0} is not a valid caching type.'.format(cache_type)) | ||
|
||
return cache_time * calc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
"""Module for the ache disk driver. | ||
""" | ||
|
||
import os | ||
|
||
from masonite.contracts.CacheContract import CacheContract | ||
from masonite.drivers.BaseCacheDriver import BaseCacheDriver | ||
|
||
from masonite.exceptions import DriverLibraryNotFound | ||
|
||
|
||
class CacheRedisDriver(CacheContract, BaseCacheDriver): | ||
"""Class for the cache redis driver. | ||
""" | ||
|
||
def __init__(self, CacheConfig, Application): | ||
"""Cache redis driver constructor | ||
Arguments: | ||
CacheConfig {config.cache} -- Cache configuration module. | ||
Application {config.application} -- Application configuration module. | ||
""" | ||
|
||
self.appconfig = Application | ||
self.cache_forever = None | ||
self.app_name = os.getenv('APP_NAME', 'masonite') | ||
|
||
config = CacheConfig.DRIVERS['redis'] | ||
|
||
try: | ||
import redis | ||
self.redis = redis | ||
except ImportError: | ||
raise DriverLibraryNotFound( | ||
"Could not find the 'redis' library. Run pip install redis to fix this.") | ||
|
||
self.connection = redis.StrictRedis( | ||
host=config['host'], | ||
port=config['port'], | ||
password=config['password'], | ||
decode_responses=True) | ||
|
||
def store(self, key, value): | ||
"""Stores content in cache file. | ||
Arguments: | ||
key {string} -- The key to store the cache file into | ||
value {string} -- The value you want to store in the cache | ||
Keyword Arguments: | ||
extension {string} -- the extension you want to append to the file (default: {".txt"}) | ||
location {string} -- The path you want to store the cache into. (default: {None}) | ||
Returns: | ||
string -- Returns the key | ||
""" | ||
|
||
self.cache_forever = True | ||
|
||
self.connection.set('{0}_cache_{1}'.format(self.app_name, key), value) | ||
|
||
return key | ||
|
||
def store_for(self, key, value, cache_time, cache_type): | ||
"""Store the cache for a specific amount of time. | ||
Arguments: | ||
key {string} -- The key to store the cache file into | ||
value {string} -- The value you want to store in the cache | ||
cache_time {int|string} -- The time as a string or an integer (1, 2, 5, 100, etc) | ||
cache_type {string} -- The type of time to store for (minute, minutes, hours, seconds, etc) | ||
Keyword Arguments: | ||
extension {string} -- the extension you want to append to the file (default: {".txt"}) | ||
location {string} -- The path you want to store the cache into. (default: {None}) | ||
Raises: | ||
ValueError -- Thrown if an invalid cache type was caught (like houes instead of hours). | ||
Returns: | ||
string -- Returns the key | ||
""" | ||
|
||
self.cache_forever = False | ||
cache_for_time = self.calculate_time(cache_type, cache_time) | ||
|
||
self.connection.set('{0}_cache_{1}'.format(self.app_name, key), value, ex=cache_for_time) | ||
|
||
return key | ||
|
||
def get(self, key): | ||
""" | ||
Get the data from a key in the cache | ||
""" | ||
|
||
return self.connection.get('{0}_cache_{1}'.format(self.app_name, key)) | ||
|
||
def delete(self, key): | ||
""" | ||
Delete file cache | ||
""" | ||
|
||
self.connection.delete('{0}_cache_{1}'.format(self.app_name, key)) | ||
|
||
def update(self, key, value): | ||
""" | ||
Updates a specific cache by key | ||
""" | ||
|
||
time_to_expire = self.connection.ttl('{0}_cache_{1}'.format(self.app_name, key)) | ||
|
||
if time_to_expire > 0: | ||
self.connection.set('{0}_cache_{1}'.format(self.app_name, key), value, ex=time_to_expire) | ||
else: | ||
self.connection.set('{0}_cache_{1}'.format(self.app_name, key), value) | ||
|
||
return key | ||
|
||
def cache_exists(self, key): | ||
""" | ||
Check if the cache exists | ||
""" | ||
|
||
return self.connection.exists('{0}_cache_{1}'.format(self.app_name, key)) | ||
|
||
def is_valid(self, key): | ||
""" | ||
Check if a valid cache | ||
""" | ||
|
||
return self.cache_exists(key) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
"""Module for specifying the Masonite version in a central location. | ||
""" | ||
|
||
VERSION = '2.0.31' | ||
|
||
VERSION = '2.0.32' |
Oops, something went wrong.