<commit_before>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PostSharp.Aspects;
using CacheAspect.Supporting;
using System.Reflection;

namespace CacheAspect.Attributes
{
    public static partial class Cache
    {
        [Serializable]
        public class Cacheable : OnMethodBoundaryAspect
        {
            private KeyBuilder _keyBuilder;
            public KeyBuilder KeyBuilder
            {
                get { return _keyBuilder ?? (_keyBuilder = new KeyBuilder()); }
            }

            #region Constructors

            public Cacheable(String groupName, CacheSettings settings, String parameterProperty)
            {
                KeyBuilder.GroupName = groupName;
                KeyBuilder.Settings = settings;
                KeyBuilder.ParameterProperties = new string[] { parameterProperty };
            }

            public Cacheable(string groupName, CacheSettings settings, string[] parameterProperties)
            {
                KeyBuilder.GroupName = groupName;
                KeyBuilder.Settings = settings;
                KeyBuilder.ParameterProperties = parameterProperties;
            }

            public Cacheable(String groupName, CacheSettings settings)
                : this(groupName, settings, string.Empty)
            {
            }

            public Cacheable(String groupName) : this(groupName, CacheSettings.Default)
            {
            }

            public Cacheable() : this(string.Empty)
            {

            }
            #endregion

            //Method executed at build time.
            public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo)
            {
                KeyBuilder.MethodParameters = method.GetParameters();
                KeyBuilder.MethodName = string.Format("{0}.{1}", method.DeclaringType.FullName, method.Name);
            }

            // This method is executed before the execution of target methods of this aspect.
            public override void OnEntry(MethodExecutionArgs args)
            {
                // Compute the cache key.
                string cacheKey = KeyBuilder.BuildCacheKey(args.Instance, args.Arguments);

                // Fetch the value from the cache.
                ICache cache = CacheService.Cache;
                MethodExecWrapper value = (MethodExecWrapper)(cache.Contains(cacheKey) ? cache[cacheKey] : null);

                if (value != null && !IsTooOld(value.Timestamp))
                {
                    // The value was found in cache. Don't execute the method. Return immediately.
                    args.ReturnValue = value.ReturnValue;
                    // args.Arguments = value.Arguments;
                    for (int i = 0; i < value.Arguments.Length; i++)
                    {
                        // args.Arguments.SetArgument(i, value.Arguments[i]);<commit_msg>Add comments to constructor of Cacheable for better developer experience as user<commit_after>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PostSharp.Aspects;
using CacheAspect.Supporting;
using System.Reflection;

namespace CacheAspect.Attributes
{
    public static partial class Cache
    {
        [Serializable]
        // TODO: Change name to CacheableAspect?
        public class Cacheable : OnMethodBoundaryAspect
        {
            private KeyBuilder _keyBuilder;
            public KeyBuilder KeyBuilder
            {
                get { return _keyBuilder ?? (_keyBuilder = new KeyBuilder()); }
            }

            #region Constructors

            /// <summary>
            /// Initializes a new instance of the Cacheable class
            /// </summary>
            public Cacheable()
                : this(string.Empty)
            {
            }

            /// <summary>
            /// Initializes a new instance of the Cacheable class
            /// </summary>
            /// <param name="groupName">Group name for the cached objects</param>
            public Cacheable(String groupName)
                : this(groupName, CacheSettings.Default)
            {
            }

            /// <summary>
            /// Initializes a new instance of the Cacheable class
            /// </summary>
            /// <param name="groupName">Group name for the cached objects</param>
            /// <param name="settings">An instance of CacheSettings for the settings of Cacheable</param>
            public Cacheable(String groupName, CacheSettings settings)
                : this(groupName, settings, string.Empty)
            {
            }

            /// <summary>
            /// Initializes a new instance of the Cacheable class
            /// </summary>
            /// <param name="groupName">Group name for the cached objects</param>
            /// <param name="settings">An instance of CacheSettings for the settings of Cacheable</param>
            /// <param name="parameterProperty">The name of the property to be used to generated the key for the cached object, when CacheSettings.UseProperty is used</param>
            public Cacheable(String groupName, CacheSettings settings, String parameterProperty)
                : this(groupName, settings, new string[] { parameterProperty })
            {
            }

            /// <summary>
            /// Initializes a new instance of the Cacheable class
            /// </summary>
            /// <param name="groupName">Group name for the cached objects</param>
            /// <param name="settings">An instance of CacheSettings for the settings of Cacheable</param>
            /// <param name="parameterProperties">The names of the properties to be used to generated the key for the cached object, when CacheSettings.UseProperty is used</param>
            public Cacheable(string groupName, CacheSettings settings, string[] parameterProperties)
            {
                KeyBuilder.GroupName = groupName;
                KeyBuilder.Settings = settings;
                KeyBuilder.ParameterProperties = parameterProperties;
            }

            #endregion

            //Method executed at build time.
            public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo)
            {
                KeyBuilder.MethodParameters = method.GetParameters();
                KeyBuilder.MethodName = string.Format("{0}.{1}", method.DeclaringType.FullName, method.Name);
            }

            // This method is executed before the execution of target methods of this aspect.
            public override void OnEntry(MethodExecutionArgs args)
            {
                // Compute the cache key.
                string cacheKey = KeyBuilder.BuildCacheKey(args.Instance, args.Arguments);

                // Fetch the value from the cache.
                ICache cache = CacheService.Cache;
                MethodExecWrapper value = (MethodExecWrapper)(cache.Contains(cacheKey) ? cache[cacheKey] : null);

                if (value != null && !IsTooOld(value.Timestamp))
                {
                    // The value was found in cache. Don't execute the method. Return immediately.
                    args.ReturnValue = value.ReturnValue;
                    // args.Arguments = value.Arguments;
                    for (int i = 0; i < value.Arguments.Length; i++)
                    {
                        // args.Arguments.SetArgument(i, value.Arguments[i]);
{'fraction_non_alphanumeric': 0.08196282925524803, 'fraction_numerical': 0.0008022462896109105, 'mean_word_length': 1.774480712166172, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6484960', 'n_tokens_mistral': 1701, 'n_tokens_neox': 1628, 'n_words': 506}