Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Commit

Permalink
Check if Firebase app has been previously initialised from cache backend
Browse files Browse the repository at this point in the history
  • Loading branch information
christippett committed Jun 22, 2019
1 parent 05178f5 commit 31d9793
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/django_firebase_cache/realtime_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
from firebase_admin.db import Reference


APP_INITIALIZED = False


class RealtimeDatabaseCache(BaseCache):
pickle_protocol = pickle.HIGHEST_PROTOCOL

Expand All @@ -24,7 +27,8 @@ def __init__(self, cache_key, params):
@property
def db(self) -> Reference:
if getattr(self, "_db", None) is None:
firebase_admin.initialize_app(options=self._options, name="DJANGO")
if not APP_INITIALIZED:
firebase_admin.initialize_app(options=self._options, name="DJANGO_CACHE")
ref = db.reference(self.db_key)
if self.key_prefix:
ref = ref.child(self.key_prefix)
Expand Down

0 comments on commit 31d9793

Please sign in to comment.