在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):stackshareio/graphql-cache开源软件地址(OpenSource Url):https://github.com/stackshareio/graphql-cache开源编程语言(OpenSource Language):Ruby 98.6%开源软件介绍(OpenSource Introduction):GraphQL CacheA custom caching plugin for graphql-ruby Goals
Why?At StackShare we've been rolling out graphql-ruby for several of our new features and found ourselves in need of a caching solution. We could have simply used InstallationAdd this line to your application's Gemfile: gem 'graphql-cache' And then execute: $ bundle Or install it yourself as: $ gem install graphql-cache Setup
class MySchema < GraphQL::Schema
query Types::Query
use GraphQL::Cache
end
module Types
class Base < GraphQL::Schema::Object
field_class GraphQL::Cache::Field
end
end Also note that if you want access to the ConfigurationGraphQL Cache can be configured in an initializer: # config/initializers/graphql_cache.rb
GraphQL::Cache.configure do |config|
config.namespace = 'GraphQL::Cache' # Cache key prefix for keys generated by graphql-cache
config.cache = Rails.cache # The cache object to use for caching
config.logger = Rails.logger # Logger to receive cache-related log messages
config.expiry = 5400 # 90 minutes (in seconds)
end UsageAny object, list, or connection field can be cached by simply adding field :calculated_field, Int, cache: true Custom ExpirationsBy default all keys will have an expiration of field :calculated_field, Int, cache: { expiry: 10800 } # expires key after 180 minutes Custom cache keysGraphQL Cache generates a cache key using the context of a query during execution. A custom key can be included to implement versioned caching as well. By providing a field :calculated_field, Int, cache: { key: :custom_cache_key } With this configuration the cache key used for this resolved value will use the result of the method Forcing the cacheIt is possible to force graphql-cache to resolve and write all cached fields to cache regardless of the presence of a given key in the cache store. This will effectively "renew" any existing cached expirations and warm any that don't exist. To use forced caching, add a value to MySchema.execute('{ company(id: 123) { cachedField }}', context: { force_cache: true }) This will resolve all cached fields using the field's resolver and write them to cache without first reading the value at their respective cache keys. This is useful for structured cache warming strategies where the cache expiration needs to be updated when a warming query is made. DevelopmentAfter checking out the repo, run To install this gem onto your local machine, run ContributingBug reports and pull requests are welcome on GitHub at https://github.com/stackshareio/graphql-cache. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct. LicenseThe gem is available as open source under the terms of the MIT License. Code of ConductEveryone interacting in the graphql-cache project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论