Git Product home page Git Product logo

dynacache's Introduction

DynaCache

DynaCache is a Python library that simplifies caching data in Amazon DynamoDB, a managed NoSQL database service provided by AWS.

With DynaCache, you can easily store and retrieve function results as a way to optimize your applications and reduce latency by caching frequently requested data. This library is particularly useful for scenarios where you want to speed up repetitive or computationally expensive operations by storing their results in DynamoDB for quick retrieval.

Features

  • DynamoDB Integration: DynaCache seamlessly integrates with AWS DynamoDB, a highly available and scalable NoSQL database service.
  • Automatic TTL Management: It manages Time-To-Live (TTL) for cached data, ensuring that stale data is automatically removed from the cache.
  • Customizable: You can specify your own Time-To-Live (TTL) for cached items, or use the default value of 1 hour.
  • Class Function Support: You can cache the results of class functions, including static and class methods.
  • Serialization: The library uses serialization to cache function results and deserialize them when retrieving cached data.
  • Easy Configuration: You can configure DynaCache through a YAML configuration file or directly provide AWS credentials and region.

Installation

You can install DynaCache using pip:

pip install dynacache

Usage

Below is some sample code using DynaCache:

from dynacache import DynamoDBCache

# Initialize DynamoDBCache
cache = DynamoDBCache(
    cache_table_name="MyCacheTable",
    aws_region="us-east-1",
    aws_access_key_id="your-access-key",
    aws_secret_access_key="your-secret-key"
)

# Define a function you want to cache
@cache.cache_response(ttl_seconds=3600)  # Cache results for 1 hour
def expensive_function(x, y):
    # Your expensive computation here
    return x + y

# Call the cached function
result = expensive_function(3, 4)  # The result is cached for subsequent calls

Configuration

You can configure DynaCache by providing AWS credentials and region directly, or by using a configuration file. Here's how to set up the configuration file:

# config.yaml
aws_region: us-east-1
aws_access_key_id: your-access-key
aws_secret_access_key: your-secret-key

Then, you can initialize DynamoDBCache using this configuration file:

cache = DynamoDBCache(cache_table_name="MyCacheTable", config_file="config.yaml")

Default boto setup

If no AWS credentials are provided, DynaCache will try to use the default credential chain provided by boto3. This means it will look for credentials in the environment variables, shared credentials file, EC2 IAM role etc. For more information, see Boto3 documentation.

License

DynaCache is released under the MIT license. See LICENSE for more details.

Contributing

This project is a basic implementation of a caching library for DynamoDB, and is open source. Feel free to submit issues or pull requests to improve it.

Contributions are welcome! Please submit a pull request with your changes. When doing so, please follow the existing code style and conventions. And add/update tests for any new functionality.

To contribute:

  1. Fork the repository
  2. Create a new branch for your changes:
git checkout -b your-branch-name
  1. Make and test your changes
  2. Add new features and tests

Disclaimer: DynaCache is not an official product or library provided by AWS. It is a third-party library developed to simplify the process of caching data in AWS DynamoDB.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.